Jak*_*les 10 asp.net asp.net-mvc forms-authentication
我的ASP.NET MVC Web应用程序允许管理员更改自己或其他用户的用户名.
用户通过呼叫登录FormsAuthentication.SetAuthCookie(userName [string], createPersistentCookie [bool]).他们通过电话登出FormsAuthentication.SignOut().我知道在更新用户名后我需要将其签名并重新登录.但是我如何检索现有的价值createPersistentCookie呢?例如,如何在重新签名时保留原来的"记住我"设置?
var cookieName = FormsAuthentication.FormsCookieName;
var request = HttpContext.Current.Request;
var cookie = request.Cookies.Get(cookieName);
if (cookie == null)
return;
try
{
var ticket = FormsAuthentication.Decrypt(cookie.Value);
//This should give you what you want...
bool isPersistent = ticket.IsPersistent;
}
catch (Exception ex)
{
//Logging
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1355 次 |
| 最近记录: |