Link to home
Start Free TrialLog in
Avatar of patelajk
patelajk

asked on

Session Variable - Does get populated sometimes

Hi

I have a page in which a session variable gets created. Basically a user clicks on a button and a session variable is created.

The session variable is used to populate the users email address on the next page. Basically it runs a sp and passes the session to it and then it spits out an email address whcih is populated on the page.

This all seems to work fine most of the time but every now and again, we get a runtime error on the line which calls the sp, basically the session is empty and there the sp fails cos of a syntax error.

This only happens every now and again but as I have no way of replicating the problem i not sure how to fix it.

Any ideas on why this could be happening and how to fix it.

Thanks



Avatar of Gyanendra Singh
Gyanendra Singh
Flag of India image

From where you are taking users email address, it may possible for that would be empty ...Please check
check your session state in your web.config

try with Inproc and stateserver

http://msdn.microsoft.com/en-us/library/ms972429.aspx

I was having the same problems I switched to stateserver and all is well..

Don't forget you'll have to make any objects you store in session serializable, if you change the state to stateserver.
Avatar of patelajk
patelajk

ASKER

Its not empty i have a function which displays "" if it is
it is null?
I currently have this in config file
<sessionState mode="InProc" cookieless="false" timeout="45" sqlConnectionString="data source=127.0.0.1;user id=sa;password=" stateConnectionString="tcpip=127.0.0.1:42424"/>

>> Don't forget you'll have to make any objects you store in session serializable, if you change the state to stateserver. >> How would i do this

are you storing objects in your session?

if so. you will have to add this: "[Serializable]" before all the objects you plan on storing in session.

Ex:
[Serializable]
    public class MySessionStoredClass
i create the session on a click of a button

so on button onclick event

Session("FIM2008collector_contact") = intContactID
if vb yes.
if C#
Session["FIM2008collector_contact"] = intContactID;
Sorry I meant thats how I am creating the Session at the moment.

Yet every now and again it doesn't create it, i will take a look at the article you posted above and see if I  find anything.... if you have any more ideas then let us know
>>>I have a page in which a session variable gets created. Basically a user clicks on a button and a session variable is created.
Maybe the user bypassed the page without clicking the button, for example directly accessing the second page through a bookmark or through the browser history. Because of this, the seesion is not populated. You should always check on your second page if the session variable is null (or Nothing in VB.NET) before you try to retrieve its value:
 

// C#
If (Session["mySessionName"] == null)
{
   Response.Redirect("previousPage.aspx");
}
else
{
  //Continue your work;
}
 
'VB.NET
If (Session("mySessionName") Is Nothing) Then
   Response.Redirect("previousPage.aspx")
Else
   'Continue your work
End If

Open in new window

are you sure it's not creating it? or your site is just losing the session state.
i think its prob to do with it losing session state. I am confident its creating the object
ASKER CERTIFIED SOLUTION
Avatar of copyPasteGhost
copyPasteGhost
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i ll give it  a go thanks for you help