Asp.net FormsAuthentication-处理用户名更改

Asp.net FormsAuthentication-处理用户名更改,asp.net,asp.net-mvc,forms-authentication,Asp.net,Asp.net Mvc,Forms Authentication,我的ASP.NET MVC web应用程序允许管理员更改自己或其他用户的用户名 用户通过调用FormsAuthentication.SetAuthCookie(用户名[string],createPersistentCookie[bool])登录。通过调用FormsAuthentication.SignOut()将其注销。我知道在更新用户名后,我需要注销并重新登录。但是如何检索createPersistentCookie的现有值呢?e、 g.在重新登录时,我如何保留他们最初的“记住我”设置 va

我的ASP.NET MVC web应用程序允许管理员更改自己或其他用户的用户名

用户通过调用
FormsAuthentication.SetAuthCookie(用户名[string],createPersistentCookie[bool])
登录。通过调用
FormsAuthentication.SignOut()
将其注销。我知道在更新用户名后,我需要注销并重新登录。但是如何检索
createPersistentCookie
的现有值呢?e、 g.在重新登录时,我如何保留他们最初的“记住我”设置

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
}