1

I want to copy a pdf from a shared folder to a project folder. So I use System.IO.File.Copy:

System.IO.File.Copy(@"\\netstore\IT\SIGN\112454.pdf", "C:\inetpub\wwwroot\myaspmvcwebapisite\temp\112454.pdf", true);

The file copies when I run the application locally on my machine but when I publish it to the server and go to the site I get:

signature-service.ts:120 {"$id":"1","Message":"An error has occurred.","ExceptionMessage":"Access to the path '\\\\netstore\\IT\\SIGN\\112454.pdf' is denied.","ExceptionType":"System.UnauthorizedAccessException","StackTrace":"   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)\r\n   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)\r\n   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)\r\n   at api.valbruna.local.Controllers.ValShip.SignatureController.Post(Int32 id)"}

How do I grant access to the site to access that file location?

Please note:

  • The site is a MVC Web API INTRANET application
  • It uses windows based authentication
  • When I say localhost I mean within visual studio(IISExpress)

What I have tried:

  • Granting EVERYONE access to the folder \\netstore\IT\SIGN\

I have looked at other posts(Access to the path is denied) on stack overflow but most of the answers say to grant access to IIS_USRS and I have given everyone access so that doesn't work.

---Update 1---

@Chris Pratt I have updated my IIS settings based on the link you provided.

  1. The identity field has been updated from NetworkService to ApplicationPoolIdentity.

enter image description here

  1. I granted full access to the <domainname>\<machinename>$

enter image description here

---Update 2---

@jp2code I turned on network discovery and I am still getting the same error.

enter image description here

---Update 3---

As a temporary workaround using an Impersonation class works in accessing the shared folder:

using (new Impersonator("username", System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName, "password"))
{
    // code that executes under the new context.
    sizingDoc.LoadFromFile(sigDocUrl);
}
Community
  • 1
  • 1
MasterProgrammer200
  • 1,021
  • 2
  • 17
  • 29
  • 1
    If this is a Windows PC, make sure "network discovery" is enabled. –  Sep 23 '16 at 17:02
  • @jp2code Thank you for your response. I don't have the proper authorizations to make that change to the server so I will have my boss turn it on. I'll let you know when he does so. – MasterProgrammer200 Sep 23 '16 at 17:12
  • @jp2code I turned on network discovery for the home or work, and Domain profiles on the server. However I still get the Access to the path '\\\\netstore\\IT\\SIGN\\112454.pdf' is denied error. Any other suggestions? – MasterProgrammer200 Sep 26 '16 at 14:53
  • Are you able to reboot both PCs? Or, at the least, log out and log back in to force all of the settings to reload. If that doesn't work, there must be something else causing your issue. –  Sep 26 '16 at 18:42
  • @jp2code I am not able to reboot the PC but I was able to log out and log back in. That didn't work but for some reason using impersonation on on a different account worked . http://stackoverflow.com/questions/4957522/file-copy-to-file-server-with-network-credential I am currently looking into why my user account when put in the impersonation can not access the netstore. But for right now impersonating the admin account works to access the necessary files on the netstore. – MasterProgrammer200 Sep 28 '16 at 17:35

1 Answers1

1

Are you saying it runs fine when hosted in a local IIS or within Visual Studio (IIS Express)? IIS Express runs under the active user account, but IIS runs under the App Pool's Identity. Granting access to IIS_USRS is enough for a local directory, but a remote directory will require authentication, which means it will authenticate via the App Pool's Identity. This article from Microsoft may give you some extra pointers in getting this up and running.

However, without customizing anything, the fact that the App Pool runs as a network service, should be enough to allow you grant access. Network services are authorized via the machine account (<domainname>\<machinename>$). So, if you authorize the network share for that account, you should be good.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
  • Thank you for your reply. I apologize for me not specifying: within Visual Studio (IIS Express). I have updated my question above with the steps I took from the link you posted. Unfortunately I'm still getting the same error. When you say authorize network share for the server do you mean like @jp2code suggested? – MasterProgrammer200 Sep 23 '16 at 18:08