我正在尝试对我的移动应用程序进行身份验证(用于在visual中运行测试),以便在单页应用程序中验证我的Web 2身份验证令牌
但是Ajax总是取消状态
我已启用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 Developer tools Log
状态:取消
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发布于 2014-01-12 20:27:04
我在DurandalAuth中做了一些更改,以启用CORS,并在另一个回购中创建了一个示例Javascript客户机
看看这个
https://github.com/yagopv/DurandalAuth/commit/4e7c09bc589345c946319b42d320e2b4d8313573
https://github.com/yagopv/DurandalAuthjsclient
也许您的主要问题是使用默认的Web属性。您应该使用Microsoft.Owin.Cors属性来使用Owin中间件。
发布于 2017-10-25 10:55:41
public static void Register(HttpConfiguration config)
{
var corsAttribute = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(corsAttribute);
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
}在应用程序级别的cors类寄存器方法中添加webapiConfig属性。
https://stackoverflow.com/questions/21031831
复制相似问题