Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

PRB: "Server Error in /ApplicationName Application" Error Message When an ASP.NET Application Uses Impersonation


View products that this article applies to.

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 '/ApplicationName' 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

↑ Back to the top


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\ServerName\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 "Symptoms" section of this article.

↑ Back to the top


Resolution

To resolve this problem, assign read and write permissions for the impersonated account on the C:\Documents and Settings\ServerName\ASPNET folder. To do this, follow these steps:
  1. In Windows Explorer, locate the C:\Document settings\ServerName\ASPNET\local settings folder.
  2. Right-click the Temp folder.
  3. Click Properties, and then click Security.
  4. Click Add, type ServerName\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.

↑ Back to the top


Status

This behavior is by design.

↑ Back to the top


More information

Create a New ASP.NET Web Application

  1. Start Microsoft Visual Studio .NET.
  2. 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.
  3. Double-click WebForm1.aspx. The code-behind page is displayed.
  4. 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
  5. 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 = "Provider=Microsoft.Jet.OLEDB.4.0;"
    		+ "Data Source=C:\\Program Files\\Microsoft Visual Studio\\VB98\\NWIND.MDB";	
    
    OleDbConnection cn = new OleDbConnection(connectString);
    //Open the connection.
    cn.Open();
    
    // Use a variable to hold the SQL statement.
    string selectString = "SELECT CustomerID, ContactName FROM Customers";
    
    // Create an OleDbCommand object.
    OleDbCommand cmd = new OleDbCommand(selectString,cn);
    
    OleDbDataReader reader = cmd.ExecuteReader();
    
    while(reader.Read())
     {	
      Response.Write(reader["CustomerID"].ToString()+ " : "+reader["ContactName"].ToString()+"<br>");
     }
    // 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 = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                                        "Data Source=C:\\Program Files\\Microsoft Visual Studio\\VB98\\NWIND.MDB"
         
            Dim cn As OleDbConnection = New OleDbConnection(connectString)
    
            'Open the connection.
            cn.Open()
    
            'Use a variable to hold the SQL statement.
            Dim selectString As String = "SELECT CustomerID, ContactName,  FROM Customers"
           
            Dim cmd As OleDbCommand = New OleDbCommand(selectString, cn)
     
            Dim reader As OleDbDataReader = cmd.ExecuteReader()
    
            While (reader.Read())
                Response.Write(reader("CustomerID").ToString() + " : " + reader("ContactName").ToString() + "<br>")
            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.

Set Impersonation

  1. In Solution Explorer, double-click the Web.config file.
  2. Under the <System.web> section, add the following element for impersonation:
    <identity impersonate="true" />
  3. Save and close the Web.config file.

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:

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 "Symptoms" section of this article.

↑ Back to the top


References

For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
306158 INFO: Implementing Impersonation in an ASP.NET Application

317012 INFO: Process and Request Identity in ASP.NET

323293 FIX: "Access Is Denied" Error Message When You Try to Access Indexing Service from ASP.NET with Impersonation Enabled

↑ Back to the top


Keywords: KB827190, kbprb, kbconfig, kbwebserver, kberrmsg

↑ Back to the top

Article Info
Article ID : 827190
Revision : 5
Created on : 10/16/2006
Published on : 10/16/2006
Exists online : False
Views : 316