HTTP Error 405.0 - Method Not Allowed in ASP.net MVC5

左心房为你撑大大i 提交于 2020-01-06 20:20:43

问题


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:

  1. Open in notepad the file: %windir%\system32\inetsrv\config\applicationhost.config
  2. In the ApplicationHost.config file, locate the <handlers> tag.
  3. Make sure that all the handlers use valid HTTP methods.
  4. Save the ApplicationHost.config file.


来源:https://stackoverflow.com/questions/34019130/http-error-405-0-method-not-allowed-in-asp-net-mvc5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!