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.
- The identity field has been updated from NetworkService to ApplicationPoolIdentity.
- I granted full access to the
<domainname>\<machinename>$
---Update 2---
@jp2code I turned on network discovery and I am still getting the same error.
---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);
}