Microsoft KB Archive/316148

= PRB: Session variables are lost intermittently in ASP.NET applications =

Article ID: 316148

Article Last Modified on 2/23/2006

-

APPLIES TO


 * Microsoft ASP.NET 1.1
 * Microsoft ASP.NET 1.0

-



This article was previously published under Q316148



SYMPTOMS
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.



CAUSE
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.



RESOLUTION
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:

307598 ASP.NET state management overview





STATUS
This behavior is by design.



Steps to reproduce the behavior
Note 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: <ol style="list-style-type: lower-alpha;"> Open Microsoft Visual Studio .NET.</li> On the File menu, point to New, and then click Project.</li> In the New Project dialog box, click Visual Basic Projects under Project Types, and then click ASP.NET Web Application under Templates.</li> In the Location text box, type http://localhost/TestWeb1 .</li> Click OK to create the project. WebForm1.aspx is added to your project by default.</li></ol> </li> In the Solution Explorer window, right-click WebForm1.aspx, and then click View Code.</li>  Add the following code to the Page_Load event procedure: Response.Write(&quot;Session Variable Test &#xa0; &quot;) If IsNothing(Session(&quot;TestVal&quot;)) Then Response.Write(&quot;TestVal old value: nothing&quot;) Session(&quot;TestVal&quot;) = 0 Else Response.Write(&quot;TestVal old value: &quot; & Session(&quot;TestVal&quot;)) End If Session(&quot;TestVal&quot;) += 1 Response.Write(&quot; TestVal new value: &quot; & Session(&quot;TestVal&quot;)) </li> On the Build menu, click Build Solution.</li> In the Solution Explorer window, right-click WebForm1.aspx, and then click View in Browser.</li> In your browser, click Refresh. Notice that the page displays the initial value of the session variable as nothing.</li> 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.</li> Leave the page open in your browser.</li> 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.</li> 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.</li> Save your changes to the Global.asax file.</li> 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.</li></ol>

<div class="references_section">