2011-06-15 43 views
3

我成功地使用了ASP.NET中的自定义主体,但我的自定义主体加载数据库数据,并且我不希望发生系统中的每个请求。ASP.Net中的自定义主体缓存

我在Application_OnPostAuthenticateRequest的Global.ascx文件中加载我的自定义主体,但它看起来会话状态在此处不可用。我想在第一次请求进入系统后,我会在哪里粘住它,以便我不必从头开始重新创建它?

protected void Application_OnPostAuthenticateRequest(Object sender, EventArgs e) 
     { 
      IPrincipal principal = HttpContext.Current.User; 

      if(principal.Identity.IsAuthenticated == true && principal.Identity.AuthenticationType == "Federation") 
      { 
       CustomPrincipal customPrincipal = null; 


        IClaimsPrincipal claimsPrincipal = (IClaimsPrincipal)principal; 

        if (claimsPrincipal == null) 
        { 
         throw new ApplicationException("We should have a claims principal at this point"); 
        } 

        customPrincipal = new CustomPrincipal(claimsPrincipal); 


       HttpContext.Current.User = customPrincipal; 
       Thread.CurrentPrincipal = customPrincipal; 

      } 
     } 

回答

1

使用高速缓存,而不是会议