1

I am getting error

Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the \\ section in the application configuration.

In my web.config and page i set enableSessionState="true"

public class PageBase : System.Web.UI.Page
{
    public PageBase()
    {
        if ((string.IsNullOrEmpty(Session["ProgramID"].ToString())) && 
            (string.IsNullOrEmpty(Session["UserID"].ToString())) && 
            (string.IsNullOrEmpty(Session["CompanyID"].ToString())) && 
            (string.IsNullOrEmpty(Session["LanguageID"].ToString())))
        {
            Response.Redirect("SessionExpire.aspx", false);
        }
    }
}

i have written this one inside a class which is inherited from Web.Ui.Page.

Can you please help me out to solve this issue.

what i am missing .

please help

thanks

user1926138
  • 1,464
  • 7
  • 34
  • 53

2 Answers2

4

Session is not available (yet) during the construction of your Page, try this instead:

protected override void OnInit(EventArgs e)
{
    if ((string.IsNullOrEmpty(Session["ProgramID"].ToString())) && 
        (string.IsNullOrEmpty(Session["UserID"].ToString())) && 
        (string.IsNullOrEmpty(Session["CompanyID"].ToString())) && 
        (string.IsNullOrEmpty(Session["LanguageID"].ToString())))
    {
        Response.Redirect("SessionExpire.aspx", false);
    }

    base.OnInit(e);
}
haim770
  • 48,394
  • 7
  • 105
  • 133
0

In my case problem went away simply by using HttpContext.Current.Response instead

Samara
  • 387
  • 2
  • 9