title: Ajax post with ASP.NET Webforms
body: <p>I want to post data to server with ajax call but i am getting an error.</p>
  
  <pre><code>  var userdata = {};
      userdata["Name"] = "Saran";
      var DTO = { 'userdata': userdata };
      $.ajax({
          type: "POST",
          contentType: "application/json; charset=utf-8",
          url: "Default.aspx/update",
          data: JSON.stringify(DTO),
          datatype: "json",
          success: function (result) {
              //do something
              alert("SUCCESS = " + result);
              console.log(result);
          },
  
          error: function (xmlhttprequest, textstatus, errorthrown) {
              alert(" conection to the server failed ");
              console.log("error: " + errorthrown);
          }
      });//end of $.ajax()
  </code></pre>
  
  <p>I have created a function in Default.aspx.cs and tried to access that function with the above call.</p>
  
  <pre><code>  [WebMethod]
          public static string update(string userdata)
          {
              return "Posted";
          }
  </code></pre>
  
  <p>Error :</p>
  
  <blockquote>
  <pre><code>POST http://localhost:33762/Default.aspx/update   401 Unauthorized 52ms
  </code></pre>
    
    <p>Message       "Authentication failed." StackTrace         null ExceptionType<br>
      "System.InvalidOperationException"</p>
  </blockquote>