Art F
Art F

Reputation: 4202

.NET MVC Access denied when trying to create Directory

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.

Upvotes: 0

Views: 2386

Answers (2)

Alexei Levenkov
Alexei Levenkov

Reputation: 100630

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.

Upvotes: 1

user959729
user959729

Reputation: 1187

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.

Upvotes: 2

Related Questions