【问题标题】:c# .net framework web api controller error 404 not foundc# .net framework web api controller error 404 not found
【发布时间】:2022-02-08 17:10:49
【问题描述】:

我是 .net framework web api c# 中的菜鸟,所以我的问题是,当我尝试接收 webhook 数据时,发送数据的 web hook 测试函数会出现 404 错误。我尝试使用 ...:3001/api/USIAccountWebhook 调用 webhook 接收器控制器。我可以毫无问题地调用 ...:3001/api/Values。

我认为我出错的控制器代码的开头:

public class USIAccountWebhookController : ApiController
{

    [System.Web.Http.Route("webhooks/accountupdated")]
    public async Task<GenericResponseDTO> AccountUpdatedAsync(AccountDTO value)
    {
        string EPrelationID;
        //SecretKey from the notification should always be checked for security.
        if (value.SecretKey != SecretKey)
        {
            throw new HttpResponseException(HttpStatusCode.Unauthorized);
        }

最好的问候, 杰伦

【问题讨论】:

  • 尝试将您的路由更改为 [System.Web.Http.Route("api/USIAccountWebhook/AccountUpdatedAsync/")]

标签: c# asp.net-web-api


【解决方案1】:

404 是一个非常常见的错误,表示您调用的 URI 不存在,您共享的控制器代码通知我们您尝试的方法的正确路由调用是:

...:3001/api/webhooks/accountupdated

如此处所述:

[System.Web.Http.Route("webhooks/accountupdated")]

为了确定,还要搜索以下内容:

 [RoutePrefix("some_url_chunks_more")]

(你需要调用方法,而不是类)

【讨论】:

    猜你喜欢
    • 2021-12-27
    • 1970-01-01
    • 2018-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-10
    • 1970-01-01
    相关资源
    最近更新 更多