29

This question have been asked like million times, but I have tried those solutions and still can't find out why this error is coming up:

Access to the path '\server1\Folder1\Folder2\Folder3\file1.dwg' is denied.

Here is the action which returns the error:

    public ActionResult Download(string fileName)
    {
        fileName = fileName + ".dwg";
        string path = Path.Combine(@"\\server1\Folder1\Folder2\Folder3\", fileName);
        return File(path, "application/octet-stream", fileName);
    }

I have tried to giving permissions to "Folder3" for multiple usernames, for example "SERVER1\NETWORK SERVICE" - Full Control.

Application is running under Default Web Site. Application is running under DefaultAppPool and DefaultAppPool has identity of "NetworkService".

Following code gives identity "NETWORK SERVICE".

WindowsIdentity identity = HttpContext.Request.LogonUserIdentity;

The application was working fine (same download directory) on my own computer, but after deploying this problem showed up.

Server is running Windows 2008 R2 SP1 and IIS 7.5.

5 Answers 5

64

Try this:

"Access to the path 'xxxxxx' is denied."

As error says you need to assign permissions to folders

  1. Right Click Folder
  2. Go to Security Tab
  3. Click on Edit
  4. Click on Add
  5. Click on Advanced
  6. Find Now
  7. Give Permission to IIS_IUSRS (Full Control)
  8. Click On OK
  9. Click On OK
  10. Click On Full Control in allow
  11. Click On OK
  12. Again Run the Application

Note: if these steps are not working, then try to give same permission to NETWORK, NETWORK SERVICE users

7

For my case, I went to the root folder of my project, right clicked on it and opened the properties window and unchecked the Read-only attribute. After clicking OK, all started working.

2

If anonymous authentication is enabled on your server set read permissions for the IUSR account. To allow access for the application pool identities set read permissions for IIS_USERS group. For UNC-path sure that there are relevant permission for your shared folder (see https://technet.microsoft.com/en-us/library/cc726004(v=ws.11).aspx for details).

1

In my case we are using IIS with accounts through domain controller. At development stage with Visual Studio (.netCore 6) during debugging i had no problem accessing, creating and modifying files in network. After i had published and host the project on IIS (version 10) the "Access Denied" error appeared.

I tried all the following methods

  1. Change permissions with full control (even to everyone) to the target folder, which did not work.
  2. Remove the "readonly" attribute from the folder, which did not work.

I have solved it by changing the application pool identity to the same credentials that i am using with domain controller. How To.

  1. Got to application pools
  2. Select the application pools that matches your website
  3. Right Click on and select "Advanced Settings"
  4. On the pop up window (below image) enter image description here

click the ... icon

5.On the new pop up window, check "Custom Account"

6.Hit OK

Now everything should work fine.

P.S. I guess that can work in an other direction, by trying to add the already Application Pool Identity in the permissions of the folder (I have not tried it).

0
-1

Please give the full control permission to your directory. Please do this -Right click on folder -Go to security -From Edit give access to IIS_USERS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.