角的$饼干只在'localhost'的工作 [英] Angular's $cookies only work on 'localhost'
问题描述
振作起来,一个陌生角/ IIS的问题是未来:
我已经创建了一个使用$ cookie来OAuth访问令牌存储登录用户后角1.4.0应用程序。
Brace yourself, a strange Angular / IIS problem is coming: I have created an Angular 1.4.0 application that uses $cookies to store the oauth access token after a user logged in.
什么作品在本地主机上精美每当我部署网站到IIS服务器失败(我试过Azure和远程的)。我不明白为什么。它始终是相同的过程,但保存/读取饼干似乎仅当地工作。
What works beautifully on localhost fails whenever I deploy the website to an IIS server (I tried Azure and a remote one). I can not understand why. It is always the same procedure but saving / reading the cookies seems to work only locally.
后端(使用API)在Azure上运行,并没有被感动。前台总是带Azure的API连接但只有工作的时候hostet本地。
The backend (with the API) runs on Azure and has not been touched. The frontend always connects with this Azure-API but does only work when hostet locally.
你有什么想法?
我的code是这样的:
Do you have any idea? My code looks like this:
$http({
url: "/api/account/login",
method: "POST",
data: loginData,
headers: {'Content-Type' : 'application/x-www-form-urlencoded; charset=utf-8'}
}).then(
function (success) {
$cookies.put('access_token', success.data.access_token);
$cookies.put('refresh_token', success.data.refresh_token);
// 'test' contains the correct token on localhost
// 'test' is undefined whenever deployed to an iis
var test = $cookies.get('access_token');
deferred.resolve(results);
},
function (error) {
deferred.reject({"loginError":-1})
}
);
难道在IIS有一个特殊的cookie政策prevents cookie的访问?
Could it be that the IIS has a special cookie policy that prevents the cookie access?
更新1:
请不要误会我的意思,我不想在IIS管理或跟踪我的会话状态。我只想被允许使用Cookie来存储我的OAuth访问令牌。
UPDATE 1: Please don't get me wrong, I do not want the IIS to manage or track my session state. I just want to be allowed to use cookies for storing my OAUTH access token.
更新2:
有趣的事实:在发送给登录程序后,服务器的第一个请求,访问令牌可以在饼干的读出。 thatfails因为 $ cookies.access_token
后都要求是不确定的。我发誓(由老神和新的),我不要删除它!
UPDATE 2:
Fun fact: At the very first request that is sent to the server after the login procedure, the access token can be read out of the cookies. Every request after thatfails because $cookies.access_token
is undefined. And I swear (by the old gods and the new) that I do not delete it!
我要感谢每一个提示或帮助!
I am thankful for every hint or help!
推荐答案
您可以登录并检查什么价值,你是从IIS获得了success.data.access_token
Can you log and check what value you are getting from IIS for success.data.access_token
如果是会话cookie标记,那么你必须检查IIS配置。
if it is session cookie token then you have to check IIS configuration.
请参考以下链接用于验证会话cookie设置
Please refer below link for validating session cookie settings
https://technet.microsoft.com /en-us/library/cc754725(v=ws.10).aspx
这篇关于角的$饼干只在'localhost'的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!