C# – IIS – Access to the path is denied

access-deniedasp.netciis

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.

Best Answer

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 Addvance
  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 Above things are not working then try to give same permission to NETWORK,NETWORK SERVICE Users