Session state is not available in this context

From: A.M (IHateSpam_at_sapm123.com)
Date: 03/30/04


Date: Mon, 29 Mar 2004 21:08:08 -0500


Hi,

Why following code returns exception:
System.Web.HttpException: Session state is not available in this context.

Do i have any other alternative?

Thanks,
Ali

protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
 if (!(HttpContext.Current.User == null))
 {
  if (HttpContext.Current.User.Identity.AuthenticationType == "Forms" )
  {
   System.Web.Security.FormsIdentity id;
   id =
(System.Web.Security.FormsIdentity)HttpContext.Current.User.Identity;
   ArrayList a = (ArrayList)Session["Rolls"];
   string[] myRoles = (string[])a.ToArray(typeof(string));
   HttpContext.Current.User = new
System.Security.Principal.GenericPrincipal(id,myRoles);
  }
 }
}



Relevant Pages