LTA*_*LTA 3 cookies asp.net-mvc forms-authentication setcookie formsauthentication
我必须在登录时设置FormsAuthenticationcookie值(FormsAuthentication.SetAuthCookie(UserDesignation, false)).现在我需要提供指定更改选项.因此,当用户更改其名称时,我需要将FormsAuthenticationcookie值从旧指定更新为新指定.
有可能吗?
如果是的话,我该怎么做?
您可以修改cookie数据,如下所示,但我最好将角色保存在单独的cookie中并使用FormsAuthentication cookie对其进行身份验证
HttpCookie cookie = FormsAuthentication.GetAuthCookie(Username, true);
var ticket = FormsAuthentication.Decrypt(cookie.Value);
var newticket = new FormsAuthenticationTicket(ticket.Version,
ticket.Name,
ticket.IssueDate,
ticket.Expiration,
true, //persistent
"user data,designation",
ticket.CookiePath);
cookie.Value = FormsAuthentication.Encrypt(newticket);
cookie.Expires = newticket.Expiration.AddHours(2);
HttpContext.Current.Response.Cookies.Set(cookie);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2847 次 |
| 最近记录: |