C# Web API 路由 - 找到多个与请求匹配的操作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17145727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Web API Routing - multiple actions were found that match the request
提问by TheJoeIaut
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?
为什么我总是得到多个操作被发现匹配请求错误?
采纳答案by Darin Dimitrov
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.
您所展示的是 MVC 控制器的路由。我希望您意识到 Web API 控制器是完全不同的东西。他们在~/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):
因此,请确保您已将{action}令牌包含在您的 Web API 路由定义中(我再次重申,这与您的 MVC 路由定义无关):
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}"
);

