asp.net成员资格 – 在Application_AuthenticationRequest设置Thread.CurrentPrincipal中没有在应用程序后设置

在Application_AuthenticationRequest的global.asax文件中,我将Thread.CurrentPrincipal设置为自定义主体.我还将HttpContext.Current.User设置为相同的主体.

但是后来在应用程序中,当我需要将Thread.CurrentPrincipal强制转换为我们的自定义类型时,我收到运行时错误说:
无法将类型为“System.Web.Security.RolePrincipal”的对象强制转换为“OurCustomPrincipal”.

Thread.CurrentPrincipal是如何重置为RolePrincipal的,更重要的是我如何将它保存在我们在global.asax中设置的CustomPrincipal中

提前致谢

解决方法

你肯定已经解决了你的问题但是以防万一,如果你使用ASP.NET的RoleProvider,RoleManagerModule会覆盖FormsAuthenticationModule创建的GenericPrincipal对象,并在PostAuthenticateRequest期间用RolePrincipal对象替换它:
http://www.asp.net/Learn/Security/tutorial-11-vb.aspx

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...