401, wenn Sie versuchen zu implementieren CORS für SharePoint

Ich würde gerne den Zugriff listdata.svc (ein sharepoint-Dienst), die sich auf domainA.contoso.com aus einer web-Anwendung befindet sich auf domainB.contoso.com - Authentifizierung scheint ein Problem zu sein.

Beim Versuch auf ListData.svc über einen JQuery-Ajax-call, mit CORS aktiviert, gibt der server 401. Wenn ich die gleiche Abfrage aus einer .htm-Seite, die ich ausführen von innerhalb von SharePoint, funktioniert der Aufruf in Ordnung, da die Domäne ist die gleiche.

SharePoint mit NTLM-mit anonymer Authentifizierung deaktiviert - ich nehme an, dass der 401 ist ein Ergebnis von windows-Anmeldeinformationen nicht an die SharePoint server - aber ich bin an einem Verlust, wie Sie diese Anmeldeinformationen nicht richtig auf den header. Ich habe xhrFields: { withCredentials: true }, aber dies scheint nicht zu korrigieren, das Authentifizierungs-Problem.

Aktiviert CORS, ich habe die folgenden HTTP-Response-Header von SharePoint im IIS:

  • Access-Control-Allow-Credentials: true
  • Access-Control-Allow-Headers:Herkunft, Content-Type, Akzeptieren
  • Access-Control-Allow-Origin: *
  • Access-Control-Request-Methoden POST, GET, HEAD, OPTIONS

Windows-Authentifizierung in IIS aktiviert ist für meine web-Anwendung, und ich nicht die "OPTIONSVerbHandler" HTTP-Handler in IIS. Drehen Sie es zu Lesen, scheint nicht, einen Unterschied zu machen.

JQuery-Ajax-Aufruf (aus der Anwendung auf subdomainB.contoso.com):

 $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        url: listUrl,
        xhrFields: { withCredentials: true },
        crossDomain:true,  
        processData: false,
        async: true,
        dataType: "json",
        converters: {
            //WCF Data Service .NET 3.5 incorrectly escapes singles quotes, which is clearly
            //not required (and incorrect) in JSON specs.
            //http://bugs.jquery.com/ticket/8320?cversion=0&cnum_hist=1
            "text json": function (textValue) {
                return jQuery.parseJSON(textValue.replace(/(^|[^\\])\\'/g, "$1'"));
            }
        },
        success: function (data, status, xhr) {
            //successFunc(data.d.results);
            alert("working!");
        },
        error: function (xhr, status, error) {
            alert("failure!");
        }
    });

HTTP-Header und der 401-Antwort:

Key Value
Request OPTIONS /_vti_bin/ListData.svc/Contacts HTTP/1.1
Accept  */*
Origin  http://domainB.contoso.com
Access-Control-Request-Method   GET
Access-Control-Request-Headers  content-type, accept
Accept-Encoding gzip, deflate
User-Agent  Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
Host    domainA.contoso.com
Content-Length  0
DNT 1
Connection  Keep-Alive
Cache-Control   no-cache

Key Value
Response    HTTP/1.1 401 Unauthorized
Server  Microsoft-IIS/7.5
SPRequestGuid   1e33061c-f555-451b-9d69-0d83eff5f5ea
WWW-Authenticate    NTLM
X-Powered-By    ASP.NET
MicrosoftSharePointTeamServices 14.0.0.4762
Access-Control-Allow-Headers    Origin, Content-Type, Accept
Access-Control-Allow-Origin *
Access-Control-Request-Methods  POST, GET, HEAD, OPTIONS
Access-Control-Allow-Credentials    true
Date    Wed, 15 May 2013 15:04:51 GMT
Content-Length  0
InformationsquelleAutor Ray | 2013-05-14
Schreibe einen Kommentar