problem with SessionState

  • Thread starter Thread starter Craig G
  • Start date Start date
C

Craig G

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,

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
 
Back
Top