Microsoft KB Archive/817033

= PRB: &quot;Access denied&quot; Error Message When You Run an ASP.NET 1.0 Application in IIS 6.0 =

Article ID: 817033

Article Last Modified on 12/3/2007

-

APPLIES TO

 Microsoft ASP.NET 1.0, when used with:  Microsoft Windows Server 2003, Standard Edition (32-bit x86)

 Microsoft Internet Information Services 6.0 

-



SYMPTOMS
When you run an ASP.NET Web Application project on a computer running Windows Server 2003 with the .NET Framework 1.0 installed, and the Internet Information Services (IIS) 6.0 is running in IIS 5.0 isolation mode, you may receive the following error message if you do not grant the seImpersonatePrivilege function to the ASPNET account:

System.Web.HttpException: Access denied to 'd:\inetpub\wwwroot\ImpersonateTest\WebForm1.aspx'. Failed to start monitoring file changes.



RESOLUTION
To resolve this problem, grant the seImpersonatePrivilege to your ASPNET account. To do so, follow these steps:
 * 1) Click Start, point to Settings, and then click Control Panel.
 * 2) Double-click Administrative Tools.
 * 3) Double-click Local Security Policy. Under Local Policies, click User Rights Assignment.
 * 4) In the details pane, double-click Impersonate a client after authentication.
 * 5) Click Add, and then assign the permission to the local account that you name ASPNET.
 * 6) Open a command prompt, and then type iisreset.



STATUS
This behavior is by design.



Create an ASP.NET Web Application Project
<ol> In Microsoft Visual Studio .NET, use Microsoft Visual Basic .NET or Microsoft Visual C# .NET to create a new ASP.NET Web Application project. By default, WebForm1.aspx is created. Name the project ImpersonateTest .</li>  Double-click Design View of WebForm1.aspx, and then replace the code that exists in the code-behind page with the following code:

Visual C# .NET Code using System; using System.IO;

namespace ImpersonateTest {   ///     /// Summary description for WebForm2. ///    public class WebForm1 : System.Web.UI.Page {       string file_name = &quot;C:\\TestFolder\\MyFile.txt&quot;; private void Page_Load(object sender, System.EventArgs e)       { if (!File.Exists(file_name)) {                   Response.Write(&quot;File not found &quot;); return; }        StreamReader sr = File.OpenText(file_name); String input; while ((input=sr.ReadLine)!=null) {                   Response.Write(input); }        sr.Close; }

#region Web Form Designer generated code override protected void OnInit(EventArgs e)       { //           // CODEGEN: This call is required by the ASP.NET Web Form Designer. //           InitializeComponent; base.OnInit(e); }       ///         /// Required method for Designer support - do not modify /// the contents of this method with the code editor. ///        private void InitializeComponent {               this.Load += new System.EventHandler(this.Page_Load); }       #endregion } } Visual Basic .NET Code Imports System.IO Imports System

Public Class WebForm1 Inherits System.Web.UI.Page


 * 1) Region &quot; Web Form Designer Generated Code &quot;

'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough> Private Sub InitializeComponent

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent End Sub

Dim file_name As String = &quot;C:\TestFolder\MyFile.txt&quot; Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 * 1) End Region

If Not File.Exists(file_name) Then

Response.Write(&quot;File not found &quot;) Return

End If

Dim sr As StreamReader = File.OpenText(file_name) Dim input As String input = sr.ReadLine While Not input Is Nothing Response.Write(input) input = sr.ReadLine End While sr.Close End Sub End Class </li> On the Build menu, click BuildSolution.</li> Create a folder named TestFolder .</li> Open Microsoft Notepad, create a text file, and then save the file as MyFile.txt in the following location: C:\TestFolder\.</li></ol>

Create a User Account

 * 1) Click Start, point to All Programs, point to Administrative Tools, and then click Computer Management.
 * 2) In Computer Management, expand System Tools, and then expand Local Users and Groups.
 * 3) Right-click Users, and then click New User.
 * 4) In the User Name text box, type ImpersonateUser. In the Password and in the Confirm Password text boxes, type the word, password . Click to clear the User must change password at next logon check box.
 * 5) Click Create, and then click Close.

Add a User Account to the IIS_WPG Group

 * 1) Click Start, point to All Programs, point to Administrative Tools, and then click Computer Management.
 * 2) In Computer Management, expand System Tools, expand Local Users and Groups, and then click Groups.
 * 3) Double-click IIS_WPG.
 * 4) In the IIS_WPG Properties dialog box, click Add to add the ImpersonateUser user to the IIS_WPG Users group.
 * 5) In the Select Users or Groups dialog box, type ServerName\ImpersonateUser in the textbox, click OK, and then click OK again.

Set Access Permissions to the Folder

 * 1) In Windows Explorer, locate TestFolder.
 * 2) Right-click TestFolder, and then click Properties.
 * 3) On the Security tab, click Add.
 * 4) Type ServerName\ImpersonateUser\, and then click OK.

Allow the following permissions for the ImpersonateAccount:
 * 1) * Read & Execute
 * 2) * List Folder Contents
 * 3) * Read
 * 4) Click OK.

Enable Impersonation for the Application
<ol> Open the Web.config file.</li>  Add an <identify> section in the <system.web> tag section as follows: <identity impersonate=&quot;true&quot; userName=&quot;servername\ImpersonateUser&quot; password=&quot;password&quot;/> </li> Save the Web.config file, and then close it.</li></ol>

Test the Application
<ol> Type the following URL in the browser:

http://localhost/ImpersonateTest/WebForm1.aspx

</li> You receive the error message mentioned in the &quot;Symptoms&quot; section.</li></ol>

<div class="references_section">