0

I am trying to copy a file to a shared path like \\192.168.0.22 with a C# Web API. However, the operation is throwing an access denied error.

A Windows application on the same machine can perform the file copy with no errors.

What could be the problem here?

SOS
  • 6,430
  • 2
  • 11
  • 29
  • 1
    Also, please be clear what user account that the app pool in IIS is running under. – mjwills Feb 07 '19 at 13:30
  • 1
    I think you possibly also want to use backslashes for UNC paths, e.g. `\\192.168.0.22` – DavidG Feb 07 '19 at 13:31
  • Authentication works differently for web apps, windows desktop apps are using permission from logged in user, web apps use an IISUSR account for file system access, that could also be the issue but we're all just guessing because you didnt provide enough info. – Daniel Feb 07 '19 at 13:36
  • If the credentials are setup correctly anybody can access the file. Sometimes the credentials allow admins to do the copy. So I suspect that the app is running using ADMIN. When an admin does the copy on a remote machine a dollar sign needed to be added to the folder name. See : https://helgeklein.com/blog/2011/08/access-denied-trying-to-connect-to-administrative-shares-on-windows-7/ – jdweng Feb 07 '19 at 13:58
  • @CharlieDrewitt Your edit changes the question a bit. – mjwills Feb 07 '19 at 20:32
  • Does it? How so? Please elaborate! – Charlie Drewitt Feb 07 '19 at 20:49
  • \\ and // aren't the same thing @CharlieDrewitt. Perhaps the OP meant the contents of their original code? – mjwills Feb 07 '19 at 22:11
  • @mjwills, thanks for pointing that out. I'll submitted another edit to change it back. Out of interest, Could you provide a source on the differences between '//' and '\\' ? It was my understanding that they were interchangeable on modern Windows (https://stackoverflow.com/questions/38428561/difference-between-forward-slash-and-backslash-in-file-path/38428899) but that '\\' was the more common notation. Thanks! edit: I can't submit an edit to change it back as it's only 2 chars, so if someone with the necessary rep wants to do that please feel free! – Charlie Drewitt Feb 08 '19 at 08:32
  • here is the code - File.Copy(rootpath,"//192.168.0.22/opend/filename") - this line works when i debug using localhost . but when in host on my iis it will say access denied. – Rajat Khandelwal Feb 11 '19 at 13:05

0 Answers0