Hello,
I have an odd issue with VWD, though I don't know that is is specific to VWD. I have some code in a Global.asax file that sets a custom princial object for the session in the Application_AcquireRequestState event.
When I run the app (CSLA's PTWeb) in VWD, the code breaks in the Application_AcquireRequestState event at this (the first) line:
Code:
if (Session["CSLA-Principal"] != null)
The error is:
Code:
Session state is not available in this context.
However, the program compiles correctly and when I launch it in IE, it runs correctly too. Perfectly.
Anyone ever encounter anything like this? The app won't run in VWD because a Session object isn't instantiated (apparently) at the time the Application_AcquireRequestState event fires, but the compiled app runs fine on IIS and in IE. Should also mention I didn't have this problem running the app in .NET 1.1/VS 2003. The Global.aspx event fired fine and set the CurrentPrincipal.
Hmm...
Is the Session object not available at this point under .Net 2.0 or something weird like that?
Thanks as always,
Bob
My Global.asax event:
Code:
public class Global : System.Web.HttpApplication
{
public Global()
{
InitializeComponent();
}
protected void Application_AcquireRequestState(Object sender, EventArgs e)
{
// set the security principal to custom BusinessPrincipal
if (Session["CSLA-Principal"] != null)
{
Thread.CurrentPrincipal = (IPrincipal)Session["CSLA-Principal"];
HttpContext.Current.User = Thread.CurrentPrincipal;
}
else
{
if (Thread.CurrentPrincipal.Identity.IsAuthenticated)
{
System.Web.Security.FormsAuthentication.SignOut();
Server.Transfer("Login.aspx");
}
}
}
private void InitializeComponent()
{
this.AcquireRequestState += new System.EventHandler(this.Application_AcquireRequestState);
}
}