【发布时间】:2017-06-23 13:12:24
【问题描述】:
我的控制器中有两个 Get 方法,其中一个带有两个字符串参数,第二个带有一个字符串参数,但是当我使用一个字符串参数调用方法时,它返回 404,而带有两个字符串参数的方法有效美好的。我认为我的路由有问题。
RouteConfig.cs:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapHttpRoute("Login", "api/{controller}/{email}/{password}",
new
{
email = UrlParameter.Optional,
password = UrlParameter.Optional
});
WebApiConfig.cs:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
控制器:
[HttpGet]
public IHttpActionResult Validate(string id)
{
//Some code here // doesn't work
}
[HttpGet]
public IHttpActionResult GetCitizen(string email, string password)
{
//Some code here //works fine
}
【问题讨论】:
标签: asp.net-web-api asp.net-mvc-routing