简体   繁体   中英

jQuery POST, Error 405 Method not allowed

I am trying to host an ASP.NET MVC4 web application with IIS 7.5. When debugging the app everything works fine (I'm assuming this is because of Windows Authentication). However, when I publish the app and browse to it I get a 405 Method not allowed error:

POST http://localhost/ 405 (Method Not Allowed)
send 
i.extend.ajax 
i.(anonymous function)
(anonymous function)

From what I've been reading this is either a problem with the Handler Mappings in IIS or some configuration is needed in the web.config. Either way, I have not found the correct solution. Could anyone tell me what my web.config should include to all POSTS? And/or how to set up the correct Handler mapping in IIS, as I am new to web development and find the number of options a bit overwhelming.

The piece of javascript that throws the error is the following:

$.post("/", { latitude: locLat, longitude: locLon, username: $('#onlineUsers').attr('itemid') });

A 405 is thrown by IIS when an HTTP verb(GET,PUT,POST,DELETE,HEAD,etc.) is requested and is not supported/disallowed by the designated handler.

You'll need to open the IIS manager -> Default Web Site -> Handler Mappings (Or the handler mappings specific to your web-application)

在此处输入图片说明

In here you'll need to play with the handler mappings as one of them is not allowing "POST" verbs.

As you are not posting to any specific page (.aspx, .ashx, etc.), it will be difficult to identify the exact handler that is causing you issues.

Handlers of interest may be:

  • ExtensionlessUrlHandler-ISAPI-4.0_32bit /64bit
  • StaticFile

Once you identify the handler your request is being routed to, double click it to open the dialogue.

在此处输入图片说明

From there click "Request Restrictions" then "Verbs"

Make sure the appropriate verb is present in the text area.

在此处输入图片说明

As I mentioned before, I'm not sure which handler is handling your request as you are not posting to any particular page (you may have URL re-writing in place that is routing your request appropriately).


If the above fails, you may need to check if WebDAV Publishing is installed and remove it (restart required).

网络DAV

也许你应该像这样修改你的 post'URl 格式:

$.post('@Url.Content("~/Attach/UpdateAttach")'

some users here are having shared hosting and not dedicated servers, so they might not be able to get access to the IIS control panel..

this is my case and here is what I found..

I have my web application on the root directory created through Godaddy control panel.. and the POST request is acknowledged ..

then I used the FileZilla to create a testing folder for my jquery ..( notice i used FileZilla , so the web application and hence the IIS of GoDaddy is not aware that I wanted this folder to be part of my we application )

then whenever I test this jQuery on this testing folder.. I get that error [405 Method not allowed]..

the solution was extremely simple :

I moved my testing page out of that testing folder created by FileZilla and located it inside a folder that was created through Godaddy control panel ( in this case the IIS will be aware that this page is part of my web application :) )

Hope that will help those on Shared hosting

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM