加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net成员资格 – 在Application_AuthenticationRequest设置Th

发布时间:2020-12-15 20:55:42 所属栏目:asp.Net 来源:网络整理
导读:在Application_AuthenticationRequest的global.asax文件中,我将Thread.CurrentPrincipal设置为自定义主体.我还将HttpContext.Current.User设置为相同的主体. 但是后来在应用程序中,当我需要将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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读