简体   繁体   中英

Web API Routing - multiple actions were found that match the request

I got this Route:

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

And this Actions:

    [System.Web.Http.HttpPost]
    [System.Web.Http.ActionName("GetLoginSeed")]
    public object GetLoginSeed()

    [System.Web.Http.HttpPost]
    [System.Web.Http.AllowAnonymous]
    [System.Web.Http.ActionName("Authenticate")]
    public object PerformLogin(JObject jr)

This is the Post Request:

    http://localhost:61971/api/Login/GetLoginSeed

Why I always get an multiple actions were found that match the request error?

I got this Route:

What you have shown is a route for MVC controllers. I hope you realize that Web API controllers are an entirely different thing. They have their own routes defined in the ~/App_Start/WebApiConfig.cs .

So make sure tat you have included the {action} token in your Web API route definition (which I repeat once again has nothing to do with your MVC route definitions):

config.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{action}"
);

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