首页
学习
活动
专区
圈层
工具
发布

Web 2认证
EN

Stack Overflow用户
提问于 2014-01-09 21:43:47
回答 2查看 1.3K关注 0票数 2

我正在尝试对我的移动应用程序进行身份验证(用于在visual中运行测试),以便在单页应用程序中验证我的Web 2身份验证令牌

但是Ajax总是取消状态

我已启用CORS如下所示

代码语言:javascript
复制
var cors = new EnableCorsAttribute("*", "*", "*") {SupportsCredentials = true};
config.EnableCors(cors);

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

Web

代码语言:javascript
复制
 <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请求

代码语言:javascript
复制
 $.ajax('http://retail.leap-tel.com/token', {
                type: "POST",
                data: data,
                xhrFields: {
                    withCredentials: true
                }

Chorme Developer tools Log

状态:取消

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 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中间件。

票数 0
EN

Stack Overflow用户

发布于 2017-10-25 10:55:41

代码语言:javascript
复制
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属性。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21031831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档