Microsoft KB Archive/827190

= PRB: &quot;Server Error in /ApplicationName Application&quot; Error Message When an ASP.NET Application Uses Impersonation =

Article ID: 827190

Article Last Modified on 10/16/2006

-

APPLIES TO


 * Microsoft ASP.NET 1.1

-





SYMPTOMS
When you upgrade the Microsoft .NET Framework version 1.0 to version 1.1, and then you run a Microsoft ASP.NET application with an impersonated account to access the Microsoft Access Database, you may receive the following error message:

Server Error in '/ ' Application.

Unspecified error

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Unspecified error



CAUSE
In the .NET Framework 1.0, ASP.NET applications use the TEMP folder that is designated by the environment variables to store temporary files. In .NET Framework 1.1, ASP.NET applications use the profile folder for the local ASPNET account to write temporary files. This profile folder is C:\Documents and Settings\ \ASPNET\TEMP. The ASPNET account has permissions to write to this folder.

However, if the ASP.NET application uses impersonation, the account that is impersonated may not have the permissions to write temporary files to this folder. Therefore, when the Web server is upgraded to .NET Framework 1.1, the application may fail with the error message that is described in the &quot;Symptoms&quot; section of this article.



RESOLUTION
To resolve this problem, assign read and write permissions for the impersonated account on the C:\Documents and Settings\ \ASPNET folder. To do this, follow these steps:
 * 1) In Windows Explorer, locate the C:\Document settings\ \ASPNET\local settings folder.
 * 2) Right-click the Temp folder.
 * 3) Click Properties, and then click Security.
 * 4) Click Add, type  \ASPNET in the Select Users or Groups box, and then click OK.
 * 5) Make sure that the Full Control checkbox is selected, and then click OK.



STATUS
This behavior is by design.



Create a New ASP.NET Web Application
 Start Microsoft Visual Studio .NET. Create a new ASP.NET Web Application by using Microsoft Visual C# .NET or Microsoft Visual Basic .NET. Name the project as WebApp1. By default, WebForm1.aspx is created. Double-click WebForm1.aspx. The code-behind page is displayed.  Add the following namespace reference at the beginning of the code-behind class file:

Visual C# .NET Code using System.Data.OleDb; Visual Basic .NET Code Imports System.Data.OleDb   Replace the Page_Load event handler with the following code:

Visual C# .NET Code private void Page_Load(object sender, System.EventArgs e) { // Use a string variable to hold the ConnectionString property. string connectString = &quot;Provider=Microsoft.Jet.OLEDB.4.0;&quot; + &quot;Data Source=C:\\Program Files\\Microsoft Visual Studio\\VB98\\NWIND.MDB&quot;;

OleDbConnection cn = new OleDbConnection(connectString); //Open the connection. cn.Open;

// Use a variable to hold the SQL statement. string selectString = &quot;SELECT CustomerID, ContactName FROM Customers&quot;;

// Create an OleDbCommand object. OleDbCommand cmd = new OleDbCommand(selectString,cn);

OleDbDataReader reader = cmd.ExecuteReader;

while(reader.Read) {   Response.Write(reader[&quot;CustomerID&quot;].ToString+ &quot; : &quot;+reader[&quot;ContactName&quot;].ToString+&quot; &quot;); } // Close the reader and the related connection. reader.Close; cn.Close; } Visual Basic .NET Code Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Use a string variable to hold the ConnectionString property. Dim connectString As String = &quot;Provider=Microsoft.Jet.OLEDB.4.0;&quot; & _ &quot;Data Source=C:\\Program Files\\Microsoft Visual Studio\\VB98\\NWIND.MDB&quot; Dim cn As OleDbConnection = New OleDbConnection(connectString)

'Open the connection. cn.Open

'Use a variable to hold the SQL statement. Dim selectString As String = &quot;SELECT CustomerID, ContactName, FROM Customers&quot; Dim cmd As OleDbCommand = New OleDbCommand(selectString, cn) Dim reader As OleDbDataReader = cmd.ExecuteReader

While (reader.Read) Response.Write(reader(&quot;CustomerID&quot;).ToString + &quot; : &quot; + reader(&quot;ContactName&quot;).ToString + &quot; &quot;) End While

'Close the reader and the related connection. reader.Close cn.Close

End Sub Note Modify the connectString variable at the beginning of the code to point to the location of your Northwind database. </li></ol>

Set Impersonation
<ol> In Solution Explorer, double-click the Web.config file.</li>  Under the <System.web> section, add the following element for impersonation: <identity impersonate=&quot;true&quot; /> </li> Save and close the Web.config file.</li></ol>

Run the ASP.NET 1.0 Application
On the Build menu, click Start.

Upgrade from .NET Framework 1.0 to .NET Framework 1.1
To download and to install the .NET Framework 1.1, visit the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/netframework/aa731542.aspx

Run the ASP.NET 1.1 Application
To run the WebApp1 application, type the following URL in Microsoft Internet Explorer:

http://locahost/WebApp1/WebForm1.aspx

You may notice the error message that is mentioned in the &quot;Symptoms&quot; section of this article.

<div class="references_section">