Monday, March 26, 2012

Please help - retrieving session variable before pageload sub

I have the following code where I need to get the data from a session variable before I've done the page load. I can't seem to do this without getting the following message:

Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive.

I am using session variables fine in other parts of the program but I'm reading them after the page load.


<%@dotnet.itags.org.Import Namespace="System.data.SqlClient" %>
<%@dotnet.itags.org.Import Namespace="System.data" %>
<script runat="server">
Dim SQLCmd as string
Dim dbConn = Session("UserConnectionString")
Sub Page_Load
...

Thanks!Just set the enableSessionState to true.

If that dosen't work, just pass the conn string in to the URL, less secure though.
Thanks for the reply! I can't use a querystring in this instance and I've tried putting a PAGE directive with enablesessionstate but it didn't work. The session variable becomes available after the pageload so I think that session state is enabled.

Any more help would be greatly appreciated!

0 comments:

Post a Comment