0

I am trying to create a folder when I deploy my application and start it on my IIS8 but I am getting this error:

UnauthorizedAccessException: Access to the path 'C:\ApplicationsFolder\CentralApplicationSettings\' is denied.

This is the code in my Startup.cs:

var centralApplicationSettingsDirectory = System.IO.Directory.CreateDirectory(Environment.GetEnvironmentVariable(MSCASGlobals.CentralApplicationSettings));

When I deploy and start my application, the folder isn't created and when I try to start the application in my browser, I get the error above.

I have tried to give read/write permissions to my application pool identity already but it still doesn't work. What else am I missing?

JianYA
  • 2,750
  • 8
  • 60
  • 136

1 Answers1

0

Have you tried add permissions for IIS_USR?

Here is the link: IIS_IUSRS and IUSR permissions in IIS8

Or

Add for Application Manifest File the following line

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

This cause your application will run with admin privileges and you can access c drive.

harmath
  • 183
  • 5
  • I added permissions for IWAM_FileSharing – JianYA Jul 20 '19 at 16:06
  • The link you gave me is to a very specific folder. I want to be able to create a folder in the c drive – JianYA Jul 20 '19 at 16:09
  • Why don't create manualy after that you can add permisson like in the link. Or is this necessary to create programatically? – harmath Jul 20 '19 at 16:20
  • its necessary to create it programatically. The thing is, if i create it in this link: C:\Inetpub\vhosts\stardocs-digital.my\dev.stardocs-digital.my, it works fine. I tried replicating the permissions but it doesn't work. – JianYA Jul 20 '19 at 16:25
  • Hello, thanks for answering. Is this a security risk? – JianYA Jul 21 '19 at 02:09
  • Yes, it is but unfortunately writing onto drive C with web application is a security risk too. – harmath Jul 21 '19 at 11:18