Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
752 views
in Technique[技术] by (71.8m points)

javascript - 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') });
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

enter image description here

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.

enter image description here

From there click "Request Restrictions" then "Verbs"

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

enter image description here

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).

WebDAV


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...