简体   繁体   中英

ASP.NET WebAPI Custom route not getting hit, returning 404

I have setup this custom route for a method in a controller:

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

The route on the controller is:

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

And I am trying to call it in Postman with this example:

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

And instead of getting the result, I am getting a 404 error.

Here is what is in my 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 }
        );
    }

Does anyone know why this is not working? This seems straightforward. Thanks in advance!

这是路线定义中的错字,缺少“ e”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM