“401 Unauthorized” erreur constante avec jquery appel à webmethod

J'ai eu du mal à trouver mon jquery appel à un webmethod de travail. Je suis d'être renvoyés par le serveur avec un "401 Unauthorized" réponse. Je dois avoir un paramètre incorrect dans le web.config ou quelque part d'autre qui serait de prévenir un appel réussi.

Votre perspicacité est apprécié!

Appel à la fonction js invoque le jquery appel

button.OnClickAction = "PageMethod('TestWithParams', ['a', 'value', 'b', 2], 'AjaxSucceeded', 'AjaxFailed'); return false;";

Fonction JavaScript qui rend le jquery appel

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 > 0) {
    for (var i = 0; i < paramArray.length; i += 2) {
        if (paramList.length > 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'); }
});
}

Méthode Web dans la page

    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();
    }
...

Réponse comme on le voit dans la console de Firebug

json: {"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"}

et

"NetworkError: 401 Unauthorized - http://localhost/Care-Provider-Home/Profile/Personal-Profile.aspx/TestWithParams" TestWithParams

J'ai regardé et lu les sites habituels sur le sujet (Encosia, et al), mais pour en profiter. Soit il me manque une pièce essentielle, ou il y a quelques subtilités dans les paramètres de sécurité de mon environnement que le fait de prévenir un appel.

Voici quelques autres potentiellement utiles anecdotes qui peut avoir un impact sur votre diagnostic:

  • Webmethods dans le code-behind
  • En utilisant le CMS Sitecore (Ne semble pas intefere, ne sait jamais)
  • IIS7
  • .NET 3.5
  • jQuery 1.3.2

J'attends vos idées et de direction--merci!

OriginalL'auteur CareMatch | 2010-02-19