【问题标题】:ASP.NET WebAPI Custom route not getting hit, returning 404ASP.NET WebAPI 自定义路由未命中,返回 404
【发布时间】:2018-02-19 19:43:11
【问题描述】:

我已经为控制器中的方法设置了这个自定义路由:

[HttpPost, Route("imagconv/{format1}/to/{format2}")]
public HttpResponseMessage imagconv( [FromUri] string format1, [FromUri] string format2)

控制器上的路由是:

[RoutePrefix("convert")]
public class DocumentConvertController : ApiController

我试图用这个例子在 Postman 中调用它:

http:// ...server... /convert/imageconv/psd/to/png

我没有得到结果,而是得到一个 404 错误。

这是我的 RouteConfig 中的内容:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }

有谁知道为什么这不起作用?这似乎很简单。提前致谢!

【问题讨论】:

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


    【解决方案1】:

    这是路由定义中的拼写错误,缺少一个“e”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-01
      • 1970-01-01
      相关资源
      最近更新 更多