views:

548

answers:

3

I'm trying to write a log file from an ASP.NET application under IIS7, but keep getting the following exception:

UnauthorizedAccessException "Access to the path 'C:\Users\Brady\Exports' is denied."

I have given write access to the iis_iusrs, iis_wpg, and aspnet users, based on various advices found by Google, but still get the error. Can someone please explain how I can create a log file in that directory, or, will creating a log directory under the web application itself automatically allow writing the file, and is this not perhaps a better solution?

+2  A: 

You need to grant permission to one of the following accounts

ASPNET - Win XP and Win 2000
NETWORK SERVICE - Win Vista and 2003

These are the defaults, if the application pool has been configured for a different process account then you would need to work with that specific account.

Mitchel Sellers
A: 

I think Mitchel's got it, but I'll add that troubleshooting these kinds of things is infinitely easier using SysInternals' Process Monitor (FileMon for legacy systems) to take away the guesswork/trial and error.

Pseudo Masochist
A: 

If you are Impersonating some other user in ASP.NET, that user account must have permission to write to that directory. I highly recommend not setting a user's personal folder path as the location to store a web application's log or data. That requires the ASP.NET worker process account to have access to that user's private folder, if they are not the same account.

Allocating a common area, for example D:\webapps\logapp\logfiles, is encouraged. With the appropriate permissions given, of course.

icelava