问题
I am continuously getting the following message while running my application.
HTTP Error 405.0 - Method Not Allowed
The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.
I dont have any clue how this happening.
I tried to run this with undoing last changes but still its not working.
Can anyone help me on this please?
回答1:
Mostly it means that your Web Server is not recognizing the HTTP method(GET,POST,DELETE,PUT ...) in the request.
First, check in the RouteConfig.cs file which action run by defult.
routes.MapRoute(name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
In this case we have action Index from Home controller that was set by default.
Then, check that action. Is there any attributes like: [HttpPost], [HttpDelete], [HttpPut], ...
If you use attribute then you maybe need to make small changes in ApplicationHost.config file to enable it:
- Open in notepad the file:
%windir%\system32\inetsrv\config\applicationhost.config - In the ApplicationHost.config file, locate the
<handlers> tag. - Make sure that all the handlers use valid HTTP methods.
- Save the ApplicationHost.config file.
来源:https://stackoverflow.com/questions/34019130/http-error-405-0-method-not-allowed-in-asp-net-mvc5