FormsAuthentication - 处理用户名的变化 [英] FormsAuthentication - handling a change of username
问题描述
我的ASP.NET MVC Web应用程序,管理员可以改变自己,或者其他用户的用户名。
用户可以通过调用记录在 FormsAuthentication.SetAuthCookie(用户名[字符串] createPersistentCookie [布尔])
。他们是通过调用注销 FormsAuthentication.SignOut()
。据我所知,在更新后的用户名我需要签署出来,并再次回。但我怎么检索的现有的 createPersistentCookie
的价值?例如我该怎么办保留其原有的记住我设置登录他们回来的时候?
VAR cookieName = FormsAuthentication.FormsCookieName;
VAR请求= HttpContext.Current.Request;
VAR饼干= request.Cookies.Get(cookieName);
如果(饼干== NULL)
返回;尝试
{
VAR票= FormsAuthentication.Decrypt(cookie.Value); //这应该给你你想要的...
布尔isPersistent = ticket.IsPersistent;
}
赶上(异常前)
{
//记录
}
My ASP.NET MVC web application allows administrators to change their own, or other users' usernames.
Users are logged in by calling FormsAuthentication.SetAuthCookie(userName [string], createPersistentCookie [bool])
. They are logged out by calling FormsAuthentication.SignOut()
. I understand that after updating the username I'd need to sign them out and back in again. But how do I retrieve the existing value of createPersistentCookie
? e.g. how do I retain their original 'remember me' setting when signing them back in?
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
}
这篇关于FormsAuthentication - 处理用户名的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!