Application_AcquireRequestState

Application_AcquireRequestState

Old forum URL: forums.lhotka.net/forums/t/2875.aspx


mking posted on Tuesday, May 15, 2007

I'm using CSLA in an ASP.NET web site.  The problem I'm experiencing is that when I set the site to run in release mode (by setting debug="false" in web.config) the WebResource.axd scripts stop working.  WebResource.axd is the thing that sends javascript to the browser for the menu, atlas controls, etc.  In debug mode, it works fine.  But in release mode, the WebResource.axd gives the following error message: 

Object reference not set to an instance of an object

System.Web.HttpContext.RequestRequiresAuthorization()

I figured out that if I remove the code in  Application_AcquireRequestState  that is in the Global.asax file, the problem goes away.  When I remove the following code, I can run my site in release mode.

If anyone could help me understand what the following code does, and why removing it makes WebResource.axd work in release mode, it would be much, much appreciated.

protected void Application_AcquireRequestState(object sender, EventArgs e)

{

      if (Csla.ApplicationContext.AuthenticationType == "Windows")

            return;

      System.Security.Principal.IPrincipal principal;

      principal = Oms.Oscar.Bo.BoHelper.MyPrincipal;

      if (principal == null)

      {

            if (Request.IsAuthenticated && Request.Path.Contains("aspx"))

            {

               // user still authenticated, but principal not on session

               // so create new principal by using logoncode stored in auth ticket

               // no need to verify password becuase user already authenticated

               string cookieName = FormsAuthentication.FormsCookieName;

               HttpCookie authCookie = Context.Request.Cookies[cookieName];

                FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);

                principal = Oms.Oscar.Bo.OmsPrincipal.GetOmsPrincipal(authTicket.Name);

               Oms.Oscar.Bo.BoHelper.MyPrincipal = (Oms.Oscar.Bo.OmsPrincipal)principal;

            }

         }

         // use the principal from Session

           Csla.ApplicationContext.User = principal;

}

mking replied on Tuesday, May 15, 2007

I found some information in another thread on this forum. 

I added the following line of code to Application_AcquireRequestState and I think this fixed the problem.

 

if (System.Web.HttpContext.Current.Session == null)

      return;

Copyright (c) Marimer LLC