AngularJS - Authentication with Bearer Token and Web API 2.0

烈酒焚心 提交于 2019-12-12 02:02:21

问题


I have the problem that even though I set the $http.defaults.headers.common.Authorization to null I am still capable of accessing the [Authorize] part of my Web API 2.0 application.

This problem doesn't arise when I start the application from scratch and try to retrieve the data via an initial GET request. This is when I get an error from the $http callback function.

Any guesses why this is happening? I am quite confident that the bearer token is stored somewhere in the browser and doesn't get deleted properly ...

Chrome (With bearer token):

Chrome (Without bearer token):

Internet Explorer (no bearer Token attribute):

First of all, the authentication property in IE is completely missing. Second, in Chrome everything works perfectly. In IE I have the issue that I can't erase the token for the logout request. The login part with the summary of the regions [Authorize] part works perfectly.


回答1:


Make sure you haven't also configured jQuery to do this, via something like $.ajaxSetup




回答2:


Try to check the request that have been set, if any Authentification header is there. Also try to verify that you are using the [Authorize] attribute from System.Web.Http and not System.Web.Mvc



来源:https://stackoverflow.com/questions/26549279/angularjs-authentication-with-bearer-token-and-web-api-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!