about C#, C++, Java, sql, java script etc.

Tuesday, January 26, 2010

Writing/reading a protected file in asp.net

Some of you may run into the error "Access to the path '...' is denied" while creating a protected file in asp.net. Well, one should first check if the user account used to execute asp.code has enough rights to access a folder you try to save the file in. As long as one doesn't use impersonation this user is either NETWORK SERVICE or ASPNET.
I created a new user account for the asp.net impersonation, added necessary rights to the protected folder but was still receiving the same "Access denied" exception. Adding the permission "Log on as a batch job" for the user account solved the problem. It seems that Windows uses the batch-queue to perform I/O operations while accessing encrypted files. This only holds if files are accessed under asp.net. Win-Forms applications don't require this permission to access encrypted files.

*Steps* to solve the problem:
  1. Open Control Panel
  2. Administrative Tools -> Local Security Settings -> User Rights Assignments
  3. Find the policy Log on as a batch
  4. Add your user account/group into it

3 comments: