System.IO access error on Cache folder in ASP.NET application
I'm working on an ASP.NET application that accesses Team Foundation Server 2010 and creates new work items. The application is running in the DefaultAppPool, using NetworkService as the identity. I'm getting the error below:
[UnauthorizedAccessException: Access to the path 'Cache\v10' is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +12892935
System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj) +1594
System.IO.Directory.CreateDirectory(String path) +311
Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore.GetDefaultCacheDirectory() +1807816
Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore.InitializeInternal() +225
The catch is that I'm using a 开发者_C百科service account to connect to TFS, since the users of this form won't have permission to add work items in TFS. I have given both Network Service and the form-specific service account full control of the application's root directory. I'm not sure how to go about trouble shooting this issue.
Our server is running Windows Server 2008 with IIS 7. The application works correctly when run in debug mode from my local dev machine.
Any suggestions?
Edit: Grant's post below is correct, from what I've been able to see, but I had already completed those steps before my original post. (That's why the path is Cache\v10 instead of the long C:\Program Files ... default path.) I gave the NetworkService account full ownership of the IIS application's root folder, but we were still getting the UnauthorizedAccessException.
We were able to work around the issue by turning the Cache folder into a network share and giving NetworkService full access to the share. I'd prefer not to have to do this, but it seems to be working correctly now. If anyone knows what I can try to do this "right," I'd be grateful.
When using the Work Item Tracking object model, it needs a folder on disk to store the metadata cache.
For a normal user, this is under C:\Users\username\AppData\Local\Microsoft\Team Foundation\3.0\Cache For Network Service, this is under C:\ProgramData\Microsoft\Team Foundation\3.0\Cache
However, in your case, it appears that Network Service doesn't have permissions to create or write to that folder.
You have two options:
- Create the folder and give the local IIS_WPG group access to the folder
- Create the folder somewhere else and give the local IIS_WPG group access to the folder, and set a key in your web.config
<appSettings><add key="WorkItemTrackingCacheRoot" value="pathtofolder"/>
More specifically, you can get the location of the folder from this code:
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"Microsoft\Team Foundation\3.0\Cache");
精彩评论