Forms身份验证情况下,能否自定义实现IIdentity接口,在Cookie中保存用户正确登录后的更多信息?
在Forms身份验证情况下,能否自定义实现IIdentity接口,在Cookie中保存用户正确登录后的更多信息,MembershipUser总是通过自定义的Provider从数据库中获取信息,但有的用户信息在应用中使用非常频繁,数据量也并不是很大,想保存到自定义的IIdentity实例中。
页面通过登录界面登录成功后调用程序集以下代码:
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(userName, false, 30);
string encTicket = FormsAuthentication.Encrypt(ticket);
HttpContext.Current.Response.Cookies.Add(
new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
CustomIdentity identity = new CustomIdentity(ticket);
string[] roles = Roles.GetRolesForUser(userName);
GenericPrincipal principal = new GenericPrincipal(identity, roles);
HttpContext.Current.User = principal;
在其它aspx页面通过Page.User.Identity.GetType().ToString()得到的仍然是"FormsIdentity",为什么?
如果在使用Forms验证情况下自定义实现IIdentity接口无效的话,应该如何解决此问题呢?是否需要继承MembershipUser增加自定义实现?
XP+.NET 2.0+VisualStudio 2005