2013-04-01 76 views
2

同一域中的3個服務器。使用表單身份驗證的自定義會員提供程由REST代理請求忽略的身份驗證Cookie

  1. ASP.net web表單與登錄(表單認證)
  2. ASP.net的WebAPI
  3. ExtJs的web應用程序的作品

認證和2之間1確定。 按預期在瀏覽器中設置Auth cookie。直接從瀏覽器使用webapi方法可以。

問題:服務器#3中的ExtJs REST代理未發送授權cookie。服務器響應401未經授權的所有OPTIONS和GET。

我真的會讚賞任何幫助。 謝謝。

請求頭:

GET /api/codigos/?aux=xtiposoli&_dc=1364785770273&page=1&start=0&limit=25&filter=%5B%7B%22property%22%3A%22nombre%22%7D%5D HTTP/1.1 
Host: webapi.pruebas.com:8888 
Connection: keep-alive 
Origin: http://users.pruebas.com:8889 
X-Requested-With: XMLHttpRequest 
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22 
Accept: */* 
Referer: http://users.pruebas.com:8889/app.html 
Accept-Encoding: gzip,deflate,sdch 
Accept-Language: es-ES,es;q=0.8 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 

響應頭:

HTTP/1.1 401 Unauthorized 
Cache-Control: no-cache 
Pragma: no-cache 
Content-Type: application/json; charset=utf-8 
Expires: -1 
Server: Microsoft-IIS/8.0 
X-AspNet-Version: 4.0.30319 
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcVG9ueU1heW9yYWxcRHJvcGJveFxQcm95ZWN0b3NcTmV0MjAxMlxTRVNcU0VTLldlYkFwaVxhcGlcY29kaWdvc1w=?= 
Access-Control-Allow-Origin: * 
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept 
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS 
Date: Mon, 01 Apr 2013 03:09:35 GMT 
Content-Length: 71 

回答

4

我管理有以下改動來解決此問題:

ExtJS的應用程序啓動:

Ext.Ajax.useDefaultXhrHeader = false; 
Ext.Ajax.withCredentials=true; 

WebApi的web.config:

<add name="Access-Control-Allow-Credentials" value="true" /> 
    <add name="Access-Control-Allow-Origin" value="http://users.pruebas.com:8889" /> 
    <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" /> 
    <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />