gpt4 book ai didi

asp.net-membership - Application_AuthenticationRequest 中设置的 Thread.CurrentPrincipal 未在应用程序中设置

转载 作者:行者123 更新时间:2023-12-04 14:21:24 24 4
gpt4 key购买 nike

在 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

关于asp.net-membership - Application_AuthenticationRequest 中设置的 Thread.CurrentPrincipal 未在应用程序中设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/809727/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com