title: Getting "401 Unauthorized" error consistently with jquery call to webmethod
body: <p>I have been struggling to get my jquery call to a webmethod to work.  I am being bounced by the server with a "401 Unauthorized" response.  I must have an incorrect setting in the web.config or somewhere else that would be preventing a successful call.</p>
  
  <p>Your insight is appreciated!</p>
  
  <h2>Call to js function the invokes the jquery call</h2>
  
  <pre><code>button.OnClickAction = "PageMethod('TestWithParams', ['a', 'value', 'b', 2], 'AjaxSucceeded', 'AjaxFailed'); return false;";
  </code></pre>
  
  <h2>JavaScript function that makes the jquery call</h2>
  
  <pre><code>function PageMethod(fn, paramArray, successFn, errorFn) {
  var pagePath = window.location.pathname;
  var urlPath = pagePath + "/" + fn;
  
  //Create list of parameters in the form:  
  //{"paramName1":"paramValue1","paramName2":"paramValue2"}  
  var paramList = '';
  if (paramArray.length &gt; 0) {
      for (var i = 0; i &lt; paramArray.length; i += 2) {
          if (paramList.length &gt; 0) paramList += ',';
          paramList += '"' + paramArray[i] + '":"' + paramArray[i + 1] + '"';
      }
  }
  paramList = '{' + paramList + '}';
  
  //Call the page method
  $.ajax({
      type: "POST",
      url: pagePath + "/" + fn,
      contentType: "application/json; charset=utf-8",
      data: paramList,
      timeout: 10000,
      dataType: "json",
      success: function(result) { alert('Overjoyed'); },
      error: function(result) { alert('No joy'); }
  });
  }
  </code></pre>
  
  <h2>Web method in page</h2>
  
  <pre><code>    public partial class WebLayout : System.Web.UI.Page
  {
  
      [WebMethod()]
      public static int TestNoParams()
      {
          return 1;
      }
  
      [WebMethod()]
      public static string TestWithParams(string a, int b)
      {
          return a + b.ToString();
      }
  ...
  </code></pre>
  
  <h2>Response as seen in Firebug console</h2>
  
  <pre><code>json: {"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"}
  </code></pre>
  
  <p>and </p>
  
  <pre><code>"NetworkError: 401 Unauthorized - http://localhost/Care-Provider-Home/Profile/Personal-Profile.aspx/TestWithParams" TestWithParams
  </code></pre>
  
  <p>I have looked at and read the usual sites on the subject (Encosia, et al), but to avail.  Either I am missing a critical piece, or there are some subtleties in the security parameters of my environment that preventing a call.</p>
  
  <p>Here are some other potentially useful tidbits that may impact your diagnosis:</p>
  
  <ul>
  <li>Webmethods in codebehind</li>
  <li>Using Sitecore CMS (Does not seem to intefere, never know)</li>
  <li>IIS7</li>
  <li>.NET 3.5</li>
  <li>jQuery 1.3.2</li>
  </ul>
  
  <p>I look forward to your insights and direction--thank you!</p>