The requested resource does not support the 'GET' HTTP method

My route is configured correctly, and my methods have a decorated tag. Am I still getting "The requested resource does not support the HTTP" GET "message?

[System.Web.Mvc.AcceptVerbs("GET", "POST")] [System.Web.Mvc.HttpGet] public string Auth(string username, string password) { // Décoder les paramètres reçue. string decodedUsername = username.DecodeFromBase64(); string decodedPassword = password.DecodeFromBase64(); return "value"; } 

Here are my routes:

 config.Routes.MapHttpRoute( name: "AuthentificateRoute", routeTemplate: "api/game/authentificate;{username};{password}", defaults: new { controller = "Game", action = "Auth", username = RouteParameter.Optional, password = RouteParameter.Optional }, constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) } ); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { controller = "Home", id = RouteParameter.Optional } ); 
+90
c # asp.net-web-api routing
Oct 07
source share
4 answers

Please use the attributes from the System.Web namespace. Http in the actions of your WebAPI:

  [System.Web.Http.AcceptVerbs("GET", "POST")] [System.Web.Http.HttpGet] public string Auth(string username, string password) {...} 

The reason it does not work is because you used attributes from the MVC System.Web.Mvc . Classes in the System.Web.Http for WebAPI .

+205
07 Oct '12 at 5:45
source

just use this attribute

 [System.Web.Http.HttpGet] 

this line of code is not needed:

 [System.Web.Http.AcceptVerbs("GET", "POST")] 
0
Jul 30 '18 at 9:52
source

In my case, the route signature was different from the method parameter. I had an identifier, but I took documentId as the parameter that caused the problem.

 [Route("Documents/{id}")] <--- caused the webapi error [Route("Documents/{documentId}")] <-- solved public Document Get(string documentId) { .. } 
0
Nov 30 '18 at 1:26
source

I had the same problem .. I already had 4 controllers that worked and worked just fine, but when I added this controller, it returned "The requested resource does not support the HTTP GET method". I tried everything here and in several other relevant articles, but was indifferent to the solution, since, as Dan B. mentioned in the answer, I already had others working fine.

I left for a while, came back and immediately realized that when I added the controller, it was nested in the "Controller" class, and not in the "ApiController" class, under which were my other controllers. I assume that I chose the wrong scaffold option to build the .cs file in Visual Studio. So I included the System.Web.Http namespace, changed the parent class, and everything works without additional attributes or routing.

0
Jan 08 '19 at 22:52
source



All Articles