0

I am trying to create a Directory in .NET using Directory.CreateDirectory, I followed the directions here to give access permission but I am still getting an UnauthorizedAccessException. Does anyone have any advice? Note, this is a web application that uses the IIS7 server.

Community
  • 1
  • 1
Art F
  • 3,992
  • 10
  • 49
  • 81

2 Answers2

2

In the directory you are attempting to create a new directory, make sure that your app pool user has Read/Write permissions for that directory. You have to specifically do that in addition to adding the user to the user groups.

user959729
  • 1,127
  • 2
  • 12
  • 19
1

2 more potential issues (+1 to user959729):

  • you are creating directory at different place than you think you are (i.e. you building path wrong)
  • the code runs under impersonated account (user's or anonymous) and such user does not have permissions to create folder (to verify try check System.Environment.UserName before creating directory). To fix you need to run code as process account.
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179