我尝试将登录信息保存在 cookie 中。在我的方法之后,cookies 注册了良好的数据。但是,当我重定向到下一页时,cookie 会丢失。我不明白为什么。如果有人可以解释我。
这是我的登录方法:
$scope.Login = function()
{
var expireDateCookies = new Date();
expireDateCookies.setHours(expireDateCookies.getHours() + 6);
// default post header to url encoded content
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
//variable who contains the authentication information
var auth = $scope.auth;
var requestGetToken = $http({ method: 'POST', url: url, headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, data: $.param({ username: auth.Login, password: auth.Password, grant_type: 'password', client_id: client_id }) });
requestGetToken.success(function (data) {
$cookieStore.put('access_token', data.access_token, { 'expires': expireDateCookies });
});
// default post header to json
$http.defaults.headers.post['Content-Type'] = 'application/json';
$window.location.href = '/CustomersList';
}
谢谢你能给我的所有帮助。