lan*_*der 4 asp.net security asp.net-mvc iprincipal
我正在尝试在.NET MVC网站中实现自定义主体和自定义标识.我创建了一个自定义主体类,它继承自IPrincipal和继承自IIdentity的自定义标识.
当用户登录时,我将Thread.CurrentPrincipal和HttpContext.Current.User都设置为我的自定义主体.当我通过调试器查看时,使用所有属性设置值.
但是,一旦请求完成,我尝试并请求任何其他页面,Thread.CurrentPrincipal和HttpContext.Current.User的类型为System.Security.Principal.GenericPrincipal,而不是我的自定义主体.
我是否需要做任何"额外"操作才能将我的自定义主体从线程或HttpContext中取出?
谢谢
请求之间的值Thread.CurrentPrincipal
和HttpContext.Current.User
不存在,它们在每个请求上重建.你最好的地方可能在Global.asax; 用原型编写一个函数:
void Application_PostAuthenticateRequest(object sender, EventArgs e)
Run Code Online (Sandbox Code Playgroud)
在每个请求上对用户进行身份验证后,应该调用它,这样您就可以根据需要设置主体.
归档时间: |
|
查看次数: |
2061 次 |
最近记录: |