Microsoft KB Archive/317955

= FIX: &quot;Failed to start monitoring directory changes&quot; error message when you browse to an ASP.NET page =

Article ID: 317955

Article Last Modified on 7/8/2005

-

APPLIES TO


 * Microsoft ASP.NET 1.0

-



This article was previously published under Q317955



SYMPTOMS
When you browse to an ASP.NET (.aspx) page, you may receive one of the following error messages:

Access denied to ' ' directory. Failed to start monitoring directory changes.

-or-

Access denied to ' '. Failed to start monitoring file changes.

For more information about the call stack traces that are associated with each of these error messages, see the &quot;More Information&quot; section.



CAUSE
To detect file changes, the process identity and the impersonated user identity must have specific permissions to all of the directories in the hierarchy of the file path for the file that ASP.NET is monitoring if any of the directories in that hierarchy have more than eight characters in their names.

Some examples of the files that ASP.NET monitors are as follows:
 * Web.config files
 * Machine.config files
 * Files in the Bin directory of an ASP.NET application
 * Cache dependency files

You receive the first error message if the Aspnet_wp.exe process identity (the ASPNET account by default) does not have permissions on at least one of the directories in the hierarchy of that file path.

You receive the second error message if the impersonated account does not have permissions on at least one of the directories in the hierarchy of that file path.



RESOLUTION
Use either of the following methods to resolve this problem.

Method 1
Make sure that all of the directory names in the hierarchy of that file path are less than nine characters long.

For example:

C:\Web\Users\MainDir\Site1

Note If you rename the directories so that the length of each directory name is now fewer than nine characters, after you make the required changes in the configuration of the Web site in Microsoft Internet Information Services (IIS) to deal with the directory renaming, you have to restart IIS.

Method 2
Grant the required permissions on all of the directories in that hierarchy to the ASP.NET process account (ASPNET by default) or to the impersonated account (if impersonation is turned on). To do this, follow these steps:  In Windows Explorer, browse to the application folder or to the virtual directory that contains the content (for example, D:\MyWeb\Users\MainDirectory\MyApplication). Right-click the folder, and then click Properties. On the Security tab, click Add. Type \ASPNET (for example, on a computer that is named Webdev, type Webdev\ASPNET ), and then click OK. If impersonation is turned on, you must also add the impersonated accounts. Allow the following permissions for the ASPNET account (and for the impersonated accounts if impersonation is turned on):  Read & Execute</li> List Folder Contents</li> Read</li></ul>

</li> Click OK to close the Properties dialog box and to save the changes.</li> Repeat steps 2 through 6 for all of the folders in the hierarchy of the path. For example:

<ul> D:\MyWeb\Users\MainDirectory</li> D:\MyWeb\Users</li> D:\MyWeb</li> D:\</li></ul>

If you want to grant more restrictive permissions to these folders, follow these steps after you complete step 5:

<ol style="list-style-type: lower-alpha;"> Click Advanced.</li> On the Permissions tab, click the permission entry for the ASPNET account (or another impersonated account), and then click Edit.</li> Click Clear All, and then click to select the Allow check box for the List Folder / Read Data permission.</li></ol>

NOTE: The application virtual directory (for example, D:\MyWeb\Users\MainDirectory\MyApplication) must have at least the permissions that are specified in step 5.</li> Restart IIS.</li></ol>

Method 3
If your computer is running IIS 6.0, grant the required permissions on all the folders in that hierarchy to the Network Service account. To do this, follow these steps: <ol> In Windows Explorer, locate the application folder or the virtual directory that contains the content (for example, D:\MyWeb\Users\MainDirectory\MyApplication).</li> Right-click the folder, and then click Properties.</li> On the Security tab, click Add.</li> Type \NETWORK SERVICE (for example, on a computer that is named Webdev, type Webdev\NETWORK SERVICE ), and then click OK. If impersonation is turned on, you must also add the impersonated accounts.</li> <li>Allow the following permissions for the Network Service account (and for the impersonated accounts if impersonation is turned on): <ul> <li>Read & Execute</li> <li>List Folder Contents</li> <li>Read</li></ul>

</li> <li>Click OK to close the Properties dialog box and to save the changes.</li> <li>Repeat steps 2 through 6 for all the folders in the hierarchy of the path. For example: <ul> <li>D:\MyWeb\Users\MainDirectory</li> <li>D:\MyWeb\Users</li> <li>D:\MyWeb</li> <li>D:\</li></ul>

If you want to grant more restrictive permissions to these folders, follow these steps after you complete step 5: <ol style="list-style-type: lower-alpha;"> <li>Click Advanced.</li> <li>On the Permissions tab, click the permission entry for the Network Service account (or another impersonated account), and then click Edit.</li> <li>Click Clear All, and then click to select the Allow check box for the List Folder / Read Data permission.</li></ol>

Note The application virtual directory (for example, D:\MyWeb\Users\MainDirectory\MyApplication) must have at least the permissions that are specified in step 5.</li> <li>Restart IIS.</li></ol>

Note These steps are only valid for Web applications that are hosted in IIS 6.0.

<div class="status_section">

STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in ASP.NET (included with the .NET Framework) 1.1.

<div class="moreinformation_section">

MORE INFORMATION
This is the call stack trace that is associated with the first error message in the &quot;Symptoms&quot; section:

<pre class="fixed_text">[HttpException (0x80004005): Access denied to 'D:\MyWeb\Users\MainDirectory\MyApplication\' directory. Failed to start monitoring directory changes.] System.Web.FileChangesMonitor.StartMonitoringDirectoryRenamesAndBinDirectory(String dir, FileChangeEventHandler callback) System.Web.HttpRuntime.StartMonitoringDirectoryRenamesAndBinDirectory System.Web.HttpRuntime.FirstRequestInit(HttpContext context)

[HttpException (0x80004005): ASP.NET Initialization Error] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)

This is the call stack trace that is associated with the second error message in the &quot;Symptoms&quot; section:

<pre class="fixed_text">[HttpException (0x80004005): Access denied to 'D:\MyWeb\Users\MainDirectory\MyApplication\SamplePage.aspx'. Failed to start monitoring file changes.] System.Web.FileChangesMonitor.StartMonitoringFile(String fileName, FileChangeEventHandler callback) System.Web.Caching.CacheDependency.Init(String[] filenames, String[] cachekeys, CacheDependency dependency, DateTime start) System.Web.Caching.CacheDependency..ctor(String filename, DateTime start) System.Web.Caching.CacheDependency..ctor(String filename) System.Web.Security.FileAuthorizationModule.OnEnter(Object source, EventArgs eventArgs) System.Web.SyncEventExecutionStep.Execute System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

If you receive one the error messages that are listed in the &quot;Symptoms&quot; section, but if the call stack trace is not the same, the cause of your error message may be different. In this case, see the articles in the &quot;References&quot; for more information.

<div class="references_section">