0

I'm hoping someone can shed some light on why I may be receiving a 405 errors on my ASP.Net VB.Net WebMethod when attemping to call from JQuery ajax method.

Server Implementation:

    <WebMethod()> _
    Public Shared Function DoSomething(id As String) As String
        Dim vm As HssViewModel = New HssViewModel()

        Dim jResult As String = JsonConvert.SerializeObject(vm)

        Return jResult
   End Function

Javscript Implementation:

  $.ajax({
            type: "POST",
            url: "mypage.aspx/DoSomething",
            contentType: "application/json; charset-utf-8",
            data: { 'id': 'ABC12345' },
            dataType: "json",
            cache: true,
            succes: function (data) {
                context = data;
                console.log(data);
            },
            error: function (err) {

                console.log("JQUERY ERROR RESPONSE: " + err.message);
            }
        });

I am consistently receiving the following error message:

POST http://localhost/mypage.aspx/DoSomething 405 (Method Not Allowed) 

I have also tried setting up the script method tag to allow a GET request but then I receive a 404

  <ScriptMethod(UseHttpGet:=True, ResponseFormat:=ResponseFormat.Json)> _

2 Answers 2

1

Your WebMethod is expecting a GET request:

<ScriptMethod(UseHttpGet:=True

but you are doing a POST request:

$.ajax({
     type: "POST",

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.

If after changing the discrepancy above the problem persist then look at your iis handler mappings.

Sign up to request clarification or add additional context in comments.

3 Comments

Sorry yes I tried both post and get, that was left over code. When I was unable to successfully POST I implemented ScriptMethod attribute to try and allow GET request.
@tafaju did you try to look at iis andler mappings?
I did but this is running in webdev vs2012 and configurations settings did nothing
0

Try adding the following lines to your web.config. I had this problem after deploying to a web server but did not experience while debugging locally. This goes in the section.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.