1
votes

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

2

2 Answers

4
votes

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);
}
0
votes

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