title: Calling PageMethod using jQuery AJAX in asp.net 4.5 Web Form Site
body: <p><strong><em>Aspx</em></strong>  </p>
  
  <pre><code>&lt;%@  Item Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %&gt;
  
  &lt;!DOCTYPE html&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;script src="Scripts/jquery-1.10.2.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
          $(document).ready(function () {
              debugger;
              source =
          {
              datatype: "json",
              datafields: [
                                  { name: 'ItemID' },
                                  { name: 'ItemName' }
              ],
              id: 'ItemURL',
              async: false
          };
  
              var itemID = '1';
              var itemName = 'food';
              $.ajax({
                  type: 'POST',
                  data: "{ itemID: '" + itemID + "', itemName:'" + itemName + "'}",
                  url: 'Default.aspx/GetAllItems',
                  contentType: 'application/json; charset=utf-8',
                  dataType: 'json',
                  success: function (data) {
                      var favoriteItems = new Array();
                      debugger;
                      for (var i = 0; i &lt; (data.d.length) ; i++) {
                          var row = {};
                          row["ItemID"] = data.d[i].ItemID;
                          row["ItemName"] = data.d[i].ItemName != null &amp;&amp; data.d[i].ItemName != undefined ? data.d[i].ItemName : '';
                          favoriteItems[i] = row;
                      }
                      source.localdata = favoriteItems;
                      var dataAdapter = new $.jqx.dataAdapter(source);
                      dataAdapter.dataBind();
                  },
                  error:
            function (XMLHttpRequest, textStatus, errorThrown) {
                debugger;
            }
              });
          });
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
          &lt;asp:ScriptManager ID="ScriptManager1" runat="server" EnableItemMethods="True" /&gt;
          &lt;div&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong><em>cs page</em></strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Script.Services;
  using System.Web.Services;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  
  public partial class _Default : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
  
      }
  
      [WebMethod]
      public static string GetAllItems(String itemID, String itemName)
      {
          return "Page Method";
      }
  }
  </code></pre>
  
  <p>The above are the code I have created.</p>
  
  <p>The problem I am facing is the webmethod (GetAllItems) is not called, but in the ajax call the success block is executed and its returning the error as "Authentication failed".</p>
  
  <p>I am including my web.config also</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
    &lt;/configSections&gt;
    &lt;connectionStrings&gt;
      &lt;add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-tcmversion3-d068790f-cbfb-40cb-b881-756e476a0411;AttachDbFilename=|DataDirectory|\aspnet-tcmversion3-d068790f-cbfb-40cb-b881-756e476a0411.mdf;Integrated Security=SSPI" providerName="System.Data.SqlClient" /&gt;
    &lt;/connectionStrings&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.5" /&gt;
      &lt;httpRuntime targetFramework="4.5" /&gt;
      &lt;pages&gt;
        &lt;namespaces&gt;
          &lt;add namespace="System.Web.Optimization" /&gt;
          &lt;add namespace="Microsoft.AspNet.Identity" /&gt;
        &lt;/namespaces&gt;
        &lt;controls&gt;
          &lt;add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" /&gt;
        &lt;/controls&gt;
      &lt;/pages&gt;
      &lt;membership&gt;
        &lt;providers&gt;
          &lt;clear /&gt;
        &lt;/providers&gt;
      &lt;/membership&gt;
      &lt;profile&gt;
        &lt;providers&gt;
          &lt;clear /&gt;
        &lt;/providers&gt;
      &lt;/profile&gt;
      &lt;roleManager&gt;
        &lt;providers&gt;
          &lt;clear /&gt;
        &lt;/providers&gt;
      &lt;/roleManager&gt;
      &lt;sessionState mode="InProc" customProvider="DefaultSessionProvider"&gt;
        &lt;providers&gt;
          &lt;add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" /&gt;
        &lt;/providers&gt;
      &lt;/sessionState&gt;
    &lt;/system.web&gt;
    &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /&gt;
      &lt;providers&gt;
        &lt;provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /&gt;
      &lt;/providers&gt;
    &lt;/entityFramework&gt;
    &lt;system.web.extensions&gt;
      &lt;scripting&gt;
        &lt;webServices&gt;
          &lt;authenticationService enabled="true" /&gt;
        &lt;/webServices&gt;
      &lt;/scripting&gt;
    &lt;/system.web.extensions&gt;
  &lt;/configuration&gt;
  </code></pre>