Loosing Session Variable

  • Thread starter Thread starter Billy Jacobs
  • Start date Start date
B

Billy Jacobs

I am having a problem with my session variable being set
to Null for no apparent reason.

I am declaring it like the following when the user logs in.

dim objUserInfo as new clsUserInfo
'Set some properties
objUserInfo.UserName = txtUserName.text.trim
objUserInfo...

'Add it to session.
Session.Add("UserInfo",objUserInfo)

Then as I move from page to page all of the sudden it
randomly is null and I get a NullReferenceError.

Is it possible that it is being garbage collected? I
thought that all Session objects were supposed to last
until the Session_End method is called.

I know it has not been called because I can still navigate
to through the pages which don't use the session
information and my site is protected by forms
authentication.

This is very frustrating.

Please help.

Don't respond if you don't know what you are talking about.

Billy Jacobs.
 
Billy Jacobs said:
I am having a problem with my session variable being set
to Null for no apparent reason.

Then as I move from page to page all of the sudden it
randomly is null and I get a NullReferenceError.

Is it possible that it is being garbage collected? I
thought that all Session objects were supposed to last
until the Session_End method is called.

You could check into this:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=uG6yBC6pCHA.1968@TK2MSFTNGP10

Also, if IIS recycles I would imagine you would lose your session state.

-- Alan
 
I was having a similar problem on my site. I wrote the
following to my ISP:

"...Assuming that you are using the in-process session
state mode and not the State Server or SQL Server modes, I
understand that session-state data is lost only if
aspnet_wp.exe or the application domain restarts. These
restarts commonly occur in the following circumstances:
1. Setting an attribute in the element of the
application's Web.config file that causes a new process to
start when a condition is met, such as memoryLimit.
2. The Global.asax or Web.config file is modified.
3. Changes to the \Bin directory of the Web application.
4. Antivirus software scans and modifies the Global.asax
file, the Web.config file, or a file in the \Bin directory
of the Web application.
5. If you enable Web garden mode in the element of the
application's Web.config file, and use in-process session-
state mode, random data loss can occur. Does your event
log file show anything regarding the conditions of startup?
...."


They wrote back the following:

"...Your apppool was recycling due to a Virtual Memory
limit that is in place with all the sites on this server.
We are in the process of deciding if this limit should be
raised and if so, to what number. We have doubled the
allowable virtual memory limit for your apppool. This
seems to have resolved the issue..."

This solved the problem for me. I'd be interested if it
solves the problem for you.

John Lewis
 
Hello Billy,

Thanks for your post. As I understand, the problem you are facing session
lost problem in an ASP .NET application. Please correct me if there is any
misunderstanding. Based on my experience and research, there are a number
of possibilities that session will be lost:

1. Client related.
2. Sever application related (for example, timeout).
3. Session management problem (inproc, state server, sql server problem).
4. Some anti-virus application might also affect this.
5. Web form or web garden related.

The following KB articles describs the detailed information on session
lost. Please check them on your side:

PRB: Session Variables Are Lost Intermittently in ASP.NET Applications
http://support.microsoft.com/?id=316148

PRB: Session Variables Are Lost If You Use FRAMESET in Internet Explorer 6.0
http://support.microsoft.com/?id=323752

PRB: Session State Is Lost in Web Farm If You Use SqlServer or StateServer
Session Mode
http://support.microsoft.com/?id=325056

INFO: Do Not Store STA Objects in Session or Application
http://support.microsoft.com/?id=243543

PRB: Storing STA COM Component in Session Locks Session Down to Single
Thread
http://support.microsoft.com/?id=243815

FIX: Severe Performance Issues When You Bind Session State to Threads in
ASPCompat Mode
http://support.microsoft.com/?id=817005

IIS 6.0 Session State May Be Lost If You Use Web Gardens with ASP
Applications
http://support.microsoft.com/?id=822171

PRB: Session Data Is Lost When You Use ASP.NET InProc Session State Mode
http://support.microsoft.com/?id=324772

BUG: Session ID Is Lost When You Close a Browser Window
http://support.microsoft.com/?id=311072

I look forward to your result.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
1. Not the client. Happens on multiple machines.
2. Not a timeout. I am using forms authentication and can
still access other parts of the web that do not use the
Session variable.
3. Using the following:
<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data
source=127.0.0.1;user id=sa;password="
cookieless="false"
timeout="20"
/>
4. MCafee (will dispable and see if this helps)
5. Dedicated Server. (No web farm)
 
Hello Billy,

Please feel free to let me know if you have any problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Apparently it was the virus software causing the problem.
We turned it off of our web app directory and the problem
went away.

Thanks,

Billy Jacobs
 
Back
Top