problem with SessionState

Discussion in 'ASP .Net' started by Craig G, Jan 27, 2005.

  1. Craig G

    Craig G Guest

    i have the code in the Page_load event of a toolbar (usercontrol)

    If Not Page.IsPostBack Then

    If Session("SecurityInfo") Is Nothing Then
    Response.Redirect("Default.aspx")
    End If

    lblUserName.Text = Session.Item("SecurityInfo").UserFullName
    lblUserRole.Text = Session.Item("SecurityInfo").Role

    subFillProfessionCombo()

    RaiseEvent SecurityDetailsLoaded()

    Dim strName As Array
    strName = Split(Request.ServerVariables("URL").ToString(), "/")
    Session("CurrentPage") = strName(UBound(strName))
    End If

    every so often it falls over on

    If Session("SecurityInfo") Is Nothing Then
    Response.Redirect("Default.aspx")
    End If

    and returns the following error

    Run-time exception thrown : System.Web.HttpException - Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive

    i'm kinda baffled as to why its only falling over sometimes and other times it works fine. and i dont know where to set enableSessionState = true
     
    Craig G, Jan 27, 2005
    #1
    1. Advertisements

  2. Craig,

    you can enable Session state on every single page. Simply set the property
    EnableSessionState to true. You can do so using the designer or by code.
    Another option is to enable session state for all pages. Open web.config and
    go to the <pages> - configuration element. Simply add the attribute
    enableSessionState="true" to it:

    <pages enableSessionState="true" ...>

    Regards,
    Michael

    i have the code in the Page_load event of a toolbar (usercontrol)

    If Not Page.IsPostBack Then
    If Session("SecurityInfo") Is Nothing Then
    Response.Redirect("Default.aspx")
    End If
    lblUserName.Text = Session.Item("SecurityInfo").UserFullName
    lblUserRole.Text = Session.Item("SecurityInfo").Role
    subFillProfessionCombo()
    RaiseEvent SecurityDetailsLoaded()
    Dim strName As Array
    strName = Split(Request.ServerVariables("URL").ToString(), "/")
    Session("CurrentPage") = strName(UBound(strName))
    End If
    every so often it falls over on
    If Session("SecurityInfo") Is Nothing Then
    Response.Redirect("Default.aspx")
    End If

    and returns the following error

    Run-time exception thrown : System.Web.HttpException - Session state can
    only be used when enableSessionState is set to true, either in a
    configuration file or in the Page directive

    i'm kinda baffled as to why its only falling over sometimes and other times
    it works fine. and i dont know where to set enableSessionState = true
     
    Michael Groeger, Jan 27, 2005
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.