weixin_33719619 2014-01-09 21:43 采纳率: 0%
浏览 71

Web API 2身份验证

I am trying to get authenticated my Mobile App ( for testing running from visual studio) to authenticate my Web API 2 Authentication Token in Single Page APP

But Ajax always cancelled with status cancelled

I have enabled CORS as below

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

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

Web Config

 <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>

My Ajax Request

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

Chorme Developer tools Log

Status : Cancelled

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
  • 写回答

2条回答 默认 最新

  • weixin_33701294 2014-01-12 20:27
    关注

    I made some changes in DurandalAuth for enabling CORS and created a sample Javascript client in another repo

    Check it out

    https://github.com/yagopv/DurandalAuth/commit/4e7c09bc589345c946319b42d320e2b4d8313573

    https://github.com/yagopv/DurandalAuthjsclient

    Perhaps your main issue is about using the default Web API CORS attribute. You should use Microsoft.Owin.Cors attribute instead for working with the Owin middleware

    评论

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭