Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms
of Use |
PRB: Session variables are lost intermittently in ASP.NET applications
This article was previously published under Q316148
Session variables may be lost intermittently in Microsoft ASP.NET applications.
When this problem occurs on a Microsoft Application Center 2000 cluster, the sessions will drop on the controller when antivirus software scans the Web.config or the Global.asax files. The scan will trigger a replication, causing sessions to be lost on each member server in turn as the file is replaced.
There are many possible causes for this problem. This article addresses one possible cause: session data that is lost because of antivirus software activity.
This problem can occur when antivirus software scans the Web application files. During the scanning process, the antivirus software may mark the Global.asax, the Web.config, and/or the Machine.config files as modified. This modification prompts the Microsoft .NET Framework restart the Web application. If the session data is stored in-process, all session data is lost whenever a Web application is restarted.
To resolve this problem, use one of the following methods:
- Configure your antivirus software so that it does not scan .asax and .config files.
- Contact the antivirus software manufacturer for instructions.
- Configure your Web application to store session data out-of-process.
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
ASP.NET state management overview
This behavior is by design.
Steps to reproduce the behaviorNote
This sample assumes that your Web application stores session data in-process (which is the default behavior).
- Follow these steps to create a Web application in Microsoft Visual Basic .NET:
- Open Microsoft Visual Studio .NET.
- On the File menu, point to New, and then click Project.
- In the New Project dialog box, click Visual Basic Projects under Project Types, and then click ASP.NET Web Application under Templates.
- In the Location text box, type http://localhost/TestWeb1.
- Click OK to create the project. WebForm1.aspx is added to your project by default.
- In the Solution Explorer window, right-click WebForm1.aspx, and then click View Code.
- Add the following code to the Page_Load event procedure:
Response.Write("<b>Session Variable Test</b><br> <br>")
If IsNothing(Session("TestVal")) Then
Response.Write("TestVal old value: <b>nothing</b>")
Session("TestVal") = 0
Response.Write("TestVal old value: " & Session("TestVal"))
Session("TestVal") += 1
Response.Write("<br>TestVal new value: " & Session("TestVal"))
- On the Build menu, click Build Solution.
- In the Solution Explorer window, right-click WebForm1.aspx, and then click View in Browser.
- In your browser, click Refresh. Notice that the page displays the initial value of the session variable as nothing.
- Click Refresh again several times. Notice that the initial value of the session variable changes to a number that increments whenever you refresh the page.
- Leave the page open in your browser.
- In Notepad, open the Global.asax file from your project's folder. The Global.asax file of this TestWeb1 project is typically located in the C:\Inetpub\wwwroot\TestWeb1\Global.asax folder.
- Move the insertion point to a blank line in the Global.asax file, and then press ENTER to add a second blank line. You must perform this step to mark the file as having been modified.
- Save your changes to the Global.asax file.
- In the browser, click Refresh again. Notice that the TestVal session variable displays an initial value of nothing. Your in-process session variables are lost.
For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
PRB: Session variables are lost in ASP Web applications
How to configure SQL Server to store ASP.NET session state
Why is my ASP.NET application restarting?
Article ID: 316148 - Last Review: February 23, 2006 - Revision: 4.3
- Microsoft ASP.NET 1.1
- Microsoft ASP.NET 1.0
|kbcaching kbconfig kbprb kbstate kbsysadmin KB316148|
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate