加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – Web Api 2为承载令牌预检CORS请求

发布时间:2020-12-17 08:11:05 所属栏目:安全 来源:网络整理
导读:我有一个具有AngularJS前端和Web Api 2后端的Web应用程序,它使用承载令牌进行身份验证。 一切都在FireFox IE,但使用Chrome,我的初始登录请求是有时候有空的。 以下是AngularJS服务的电话: $ http.post(http:// localhost:55483 / token,data,{header
我有一个具有AngularJS前端和Web Api 2后端的Web应用程序,它使用承载令牌进行身份验证。

一切都在FireFox& IE,但使用Chrome,我的初始登录请求是有时候有空的。

以下是AngularJS服务的电话:

$ http.post(http:// localhost:55483 / token,data,{headers:{‘Content-Type’:’application / x-www-form-urlencoded’}})。success(function(response) ..});

预检要求被“允许访问控制原点”错误地踢回来。

但是,如果我再次单击登录按钮(从而重新发送上述请求)一切正常。

任何想法如何防止/陷阱/处理这个?

PS:我使用LOC

context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin",new[] { "*" });

在ApplicationOAuthProvider.cs文件中将CORS allow-header放在/ Token请求上,这在IE,FireFox以及有时在Chrome中可以正常工作。

以下是花式评论:

Figured this out with help from post by LeftyX on Jun 29:
– Move
this LOC app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); to the
FIRST LINE in the ConfigureAuth method of Startup.Auth.cs.
– Then,
REMOVE this LOC
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin",
new[] { "*" });
from the GrantResourceOwnerCredentials() method of
ApplicationOAuthProvide.cs.

Preflight CORS-request them gets
handled properly,and then the actual requet goes through

谢谢你,救了我整整一天。
因为它发生在许多人身上,我把你的评论给其他人可以看到的答案框。

我不想为此投票。请评论我的答案

谢谢

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读