Custom Key Caching in ASP.Net

I successfully work with a user director in ASP.NET, but my user master data loads the database, and I do not want this to happen on every request to the system.

I am loading my custom principle into the Global.ascx file in Application_OnPostAuthenticateRequest, but it seems the session state is not available here. Where should I stick to it after the first request to the system so that I don't have to recreate it from scratch?

 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;

            }
        }
+3
source share
1 answer

Use cache instead of session

+1
source

All Articles