2014-01-09 62 views
2

我試圖得到驗證我的手機軟件(用於測試從Visual Studio運行)來驗證我的Web API 2身份驗證令牌在單頁APP的Web API 2認證

但阿賈克斯總是取消與狀態取消

我已經啓用CORS如下

var cors = new EnableCorsAttribute("*", "*", "*") {SupportsCredentials = true}; 
config.EnableCors(cors); 

//Use only bearer token authentication 
      config.SuppressDefaultHostAuthentication(); 

Web配置

<system.web> 
    <authentication mode="None" /> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5" /> 
    <roleManager enabled="true" /> 
    <httpModules> 
     <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" /> 
     <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" /> 
     <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" /> 
    </httpModules> 
    </system.web> 

我的Ajax請求

$.ajax('http://retail.leap-tel.com/token', { 
       type: "POST", 
       data: data, 
       xhrFields: { 
        withCredentials: true 
       } 

Chorme開發工具登錄

狀態:已取消

Request URL:http://retail.leap-tel.com/token 
Request Headersview source 
Accept:*/* 
Cache-Control:no-cache 
Content-Type:application/x-www-form-urlencoded; charset=UTF-8 
Origin:http://localhost:1539 
Pragma:no-cache 
Referer:http://localhost:1539/index.html 
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 
Form Dataview sourceview URL encoded 

回答

0

工作添加cors屬性在webapiConfig類register方法應用水平。

+0

代碼的一部分從灰色框中輸出。請改進此以提高可讀性 –