c# – Access to the path is denied

c# – Access to the path is denied

Access to the path C:inetpubwwwrootmysiteimagessavehere is denied

Read the message carefully. You are trying to save to a file that has the same name as the directory. That cannot work, you cant overwrite a directory filled with files with a single new file. That would cause undiagnosable data loss, Access to the path is denied is the file system fighting back to prevent that from happening.

The exception message is not ideal, but it comes straight from the OS and they are cast in stone. The framework often adds extra checks to generate better messages, but this is an expensive test on a network. Perf is a feature too.

You need to use a name like C:inetpubwwwrootmysiteimagessaveheremumble.jpg. Consider Path.Combine() to reliably generate the path name.

You need to find out from the application pool for the website what is the identity it is running under (by default this is Application Pool Identity) and grant that the correct permissions.

c# – Access to the path is denied

I was having the same problem while trying to create a file on the server (actually a file that is a copy from a template).

Heres the complete error message:

{ERROR} 08/07/2012 22:15:58 - System.UnauthorizedAccessException: Access to the path C:inetpubwwwrootSAvETemplatesCover.pdf is denied.

I added a new folder called Templates inside the IIS app folder. One very important thing in my case is that I needed to give the Write (Gravar) permission for the IUSR user on that folder. You may also need to give Network Service and ASP.NET v$.# the same Write permission.

enter

After doing this everything works as expected.

Leave a Reply

Your email address will not be published. Required fields are marked *