0
2つの文字列パラメータを持つ2つのGetメソッドと、1つの文字列パラメータを持つメソッドへの呼び出し時に404を返します。 2つの文字列パラメータを使用するメソッドは正常に動作します。私はルーティングに問題があると思う。WebApi actionmethod with string parameter notFound
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
}
役立ちます
希望のように呼び出すことができます呼び出し中を追加するだけで上記の、私はあなたの助けに感謝します。ありがとうございました。 – Jack
答えとしてマークしてください –