problem with SessionState

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
 
M

Michael Groeger

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top