2017-06-23 11 views
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 
     } 

答えて

0

あなたは属性ルーティングで試すことができますか?同様に、あなたの検証方法は属性

[Route("api/<controllername>/Validate")] 

、あなたは、これはそれが動作

+0

役立ちます

http://<localhost>:<port>/api/<controllername>/validate?id=123 

希望のように呼び出すことができます呼び出し中を追加するだけで上記の、私はあなたの助けに感謝します。ありがとうございました。 – Jack

+0

答えとしてマークしてください –