View Single Post
  #3 (permalink)  
Old December 29th, 2007, 08:57 PM
Bob Bedell Bob Bedell is offline
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hi Imar,

Definitely a quirky problem that appears to have a variety of manifestations.

The problem is caused by a session state acquisition conflict between the handlers in Global.asax (AcquireRequestState in my case) and WebResource.axd. In ASP.NET 2.0, WebResource.axd is used internally by the .NET Framework to retrieve embedded resources, such as the WebUIValidation.js script file that is used for Validation controls and Menu.js script file for Menu controls. My problem involved being unable to load WebUIValidation.js.

Clear explanations of the issue aren't easy to come by, but after three days of googling I hit this which pointed me toward a fix:

http://jeffbergman.com/cs/blogs/csje.../07/27/10.aspx

I finally worked the issue out today with someone on the CSLA forum:

http://forums.lhotka.net/forums/thread/20057.aspx

My original AcquireRequestState event looked like this, and prevented the request to WebResource.axd from suceeding:

Code:
protected void Application_AcquireRequestState(Object sender, EventArgs e)
    {

         if (Session["CSLA-Principal"] != null)
         {
            System.Threading.Thread.CurrentPrincipal = (System.Security.Principal.IPrincipal)Session["CSLA-Principal"];
            HttpContext.Current.User = System.Threading.Thread.CurrentPrincipal;
        }
        else
        {
            if (System.Threading.Thread.CurrentPrincipal.Identity.IsAuthenticated)
            {
                System.Web.Security.FormsAuthentication.SignOut();
                Server.Transfer("Login.aspx");
            }
        }
    }
With the following version, wrapped with a session null check, WebResource.axd loads WebUIValidation.js sucessfully, and my validation controls work as advertised:

Code:
protected void Application_AcquireRequestState(object sender, EventArgs e)
    {
        if (HttpContext.Current.Session == null)
        {
            //do nothing
        }
        else
        {
            if (Session["CSLA-Principal"] != null)
            {
                System.Threading.Thread.CurrentPrincipal = (System.Security.Principal.IPrincipal)Session["CSLA-Principal"];
                HttpContext.Current.User = System.Threading.Thread.CurrentPrincipal;
            }
            else
            {
                if (System.Threading.Thread.CurrentPrincipal.Identity.IsAuthenticated)
                {
                    System.Web.Security.FormsAuthentication.SignOut();
                    Server.Transfer("Login.aspx");
                }
                else
                {
                    System.Threading.Thread.CurrentPrincipal = (System.Security.Principal.IPrincipal)Session["CSLA-Principal"];
                    HttpContext.Current.User = System.Threading.Thread.CurrentPrincipal;
                }
            }
        }
    }


Anyway, all is well, all issues resolved. Hope you had some good R & R.

Best,

Bob