6

I've searched through loads of different existing SO questions related to a similar issue, but I've not been able to find anything relevant to my issue.

I have the following jQuery code:

$.ajax({
   url: "Index.aspx/DeclineRequest"
   , type: 'POST'
   , contentType: 'application/json; charset=utf-8'
   , dataType: 'json'
   , data: JSON.stringify({ RequestId: requestId })
});

I'm using a very similar technique to POST data on another ASP.NET web application, and this works fine. However, this application is returning the following error:

"NetworkError: 405 Method Not Allowed - http://localhost:57255/....."

I can't find anything different about these 2 applications, so I'm confused as to why this isn't working.

This only difference between these 2 applications which I can think of, is that the one that is working is .NET 2.0, and the one that isn't working is .NET 3.5.

I've tried adding the following to my web.config, but I still get the same 405 error:

<webServices>
   <protocols>
     <add name="HttpPost"/>     
     <add name="HttpPostLocalhost"/>   
   </protocols>      
</webServices>

How can I resolve this issue?

UPDATE (16:40): I've moved this application to IIS, and the 405 error is no longer being returned. Our development environment however is localhost only. Why would this only error on localhost?

Curt
  • 94,964
  • 60
  • 257
  • 340
  • Can you show us your'e `DeclineRequest` method? – ŁukaszW.pl Apr 19 '12 at 12:01
  • Is it similar to http://stackoverflow.com/questions/7430492/twitter-search-api-networkerror-405-method-not-allowed?? – huMpty duMpty Apr 19 '12 at 12:01
  • @ŁukaszW.pl `DeclineRequest` method is simply calling `return "Hello World"` at the moment. I don't think this is the issue as typing any method name returns the same error. I've deliberately misspelt the method in some tests to check this. – Curt Apr 19 '12 at 12:58

6 Answers6

1

405 errors often arise with the POST method. You may be trying to introduce some kind of input form on the Web site, but not all ISPs allow the POST method necessary to process the form.

All 405 errors can be traced to configuration of the Web server and security governing access to the content of the Web site, so should easily be explained by your ISP.

http://www.checkupdown.com/status/E405.html

I would turn IIS Logging on to check requests. Also get Fiddler to see what is going on behind the scenes

Curt
  • 94,964
  • 60
  • 257
  • 340
Dimitri
  • 6,595
  • 4
  • 31
  • 49
  • I'm just doing this through `localhost` at the moment using VS 2010, so I don't have any IIS Logging. – Curt Apr 19 '12 at 13:01
  • I have seen a lot of inconsistencies between the ways IIS and VS work. I'd try setting up IIS host and go from there. – Dimitri Apr 19 '12 at 13:06
  • This is working fine for my other application though, running on the same machine, with almost identical code. So installing IIS doesn't seem like the solution. – Curt Apr 19 '12 at 13:08
  • okay. But you can still get Fiddler and examine request/response – Dimitri Apr 19 '12 at 13:11
  • I've downloaded fiddler but it's not really telling me much more than FireBug does – Curt Apr 19 '12 at 13:21
  • contentTypeString Default: 'application/x-www-form-urlencoded' When sending data to the server, use this content-type. Default is "application/x-www-form-urlencoded", which is fine for most cases. – Dimitri Apr 19 '12 at 13:22
1

Maybe late to the party but, try adding to your Web.Config file:

< handlers >
   ....
       < remove name="WebDAV" />
   ....
< /handlers >

This article explains what could be causing the problem:

http://www.asp.net/web-api/overview/testing-and-debugging/troubleshooting-http-405-errors-after-publishing-web-api-applications

Stralos
  • 4,105
  • 4
  • 18
  • 38
0

url: "Index.aspx/DeclineRequest" shouldn't be url: "Index.aspx?DeclineRequest" should it?

Sorry for the rather obvious suggestion, I've not seen a url like that before. You are rewriting it?

Neil Thompson
  • 6,116
  • 2
  • 25
  • 50
  • 2
    That's a WebMethod call format that calls DeclineRequest method defined in Index.aspx codebehind. – Dimitri Apr 19 '12 at 12:12
0

check the request ur sending to the server
the parameters to declineRequest is a object with a property of RequesId OR a string(or some other datatype) name RequestId cuz in the latter case u can just send data as JSON or a plain string like RequestId=requestId
so try replacing JSON.stringify({ RequestId: requestId }) with something more appropriate

Parv Sharma
  • 11,976
  • 4
  • 43
  • 78
0

My guess is: In the request you are saying that returned content will be JSON, but you are returning plain string which is in incorrect format... Try return correct JSON or change content type to plain text for test...

ŁukaszW.pl
  • 9,244
  • 5
  • 34
  • 59
-3

remove this code dataType: 'json' from your code and run

Kasun
  • 6,323
  • 2
  • 12
  • 8