Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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') });
like image 244
Matt Avatar asked Nov 06 '12 19:11

Matt


People also ask

How do I fix 405 Method not allowed in Ajax?

How to solve it? The simplest way is to enable CORS (enable the necessary headers) on the server. If you don't have server-side access to it, you can mirror the web service from somewhere else, and then enable CORS there.

What does 405 Method Not Allowed mean?

The HyperText Transfer Protocol (HTTP) 405 Method Not Allowed response status code indicates that the server knows the request method, but the target resource doesn't support this method.


1 Answers

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

like image 53
Brandon Boone Avatar answered Sep 19 '22 14:09

Brandon Boone