[英]FormsAuthentication Cookie Not Saving
我有两个登录页面。 一种用于管理员用户,另一种用于客户。
他们都执行以下代码(在授权之后),以将cookie添加到Response
。 然后将两个页面重定向到提供的URL(我在这里不进行重定向,因为我在admin上做了一些额外的检查)
public static string SetAuthCookie<T>
(this HttpResponse responseBase, string name, bool rememberMe, T userData)
{
/// In order to pickup the settings from config, we create a default cookie
/// and use its values to create a new one.
var cookie = FormsAuthentication.GetAuthCookie(name, true);
var ticket = FormsAuthentication.Decrypt(cookie.Value);
var newTicket = new FormsAuthenticationTicket(
ticket.Version,
ticket.Name,
ticket.IssueDate,
ticket.Expiration,
true,
Newtonsoft.Json.JsonConvert.SerializeObject(userData),
ticket.CookiePath
);
var encTicket = FormsAuthentication.Encrypt(newTicket);
/// Use existing cookie. Could create new one but would have to copy settings over...
cookie.Expires = (rememberMe ? DateTime.Now.AddDays(62) : DateTime.MinValue);
cookie.Value = encTicket;
responseBase.Cookies.Set(cookie);
return FormsAuthentication.GetRedirectUrl(name, true /*This Is Ignored*/);
}
管理员
现在,管理员按照提示进行操作。 添加cookie并重定向到管理员欢迎屏幕。
顾客
客户登录区域只是没有做同样的事情(请参见下面的屏幕抓图)。
我认为问题可能出在本地浏览器上。
不,尝试过:使用私有/隐身模式的不同浏览器。
我认为这可能是Cookie的设置。
怎么可能? 它们都使用相同的代码。
也许是web.config
(在他们尊敬的目录中)?
不,只是<authorization>
规则
Cookie可能有问题吗?
不,看起来不错。 同一域,HTTPS。 一切都很好
与RememberMe
?
不,无论是否尝试
太...了。
我忘了排除( [JsonIgnore]
)一个获取一些额外数据的属性(设置cookie不需要)。 这被包括在内,显然使我的cookie太大而无法保存。
哎呀。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.