【发布时间】:2011-08-14 18:07:20
【问题描述】:
我在 global.asax 中使用 Application_PostAuthenticateRequest 事件来创建自定义 IPrincipal 对象
void Application_PostAuthenticateRequest(object sender, EventArgs args)
{
if (Context.User.Identity.IsAuthenticated == true)
if (Context.User.Identity.AuthenticationType == "Forms")
{
Context.User = new CustomPrincipal(Context.User);
Thread.CurrentPrincipal = Context.User;
}
}
在我想要获取有关登录用户的更多信息的应用程序中使用。我认为它会在用户进行身份验证时被调用一次,但我注意到它会在每个页面请求中为同一个登录用户调用几次。我发现即使从 AppThemes 请求图像也会调用这个方法!
我应该在哪里创建该对象以避免为每个用户多次调用此方法?
【问题讨论】:
标签: asp.net forms-authentication