Application_AuthenticationRequest 中设置的 Thread.CurrentPrincipal 稍后不会在应用程序中设置

2024-03-22

在 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 http://www.asp.net/Learn/Security/tutorial-11-vb.aspx

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Application_AuthenticationRequest 中设置的 Thread.CurrentPrincipal 稍后不会在应用程序中设置 的相关文章

随机推荐