There's a file on my network - we'll say it's sitting at the following location:
server-name/folder1/folder2/file.xlsx
In my webapp, I'm trying to download this file when a user clicks on a link.
If I run the webapp locally, it works fine. When I run it off of my hosting server, however, it gives me an error:
System.IO.IOException: Logon failure: unknown user name or bad password.
I'm currently using the following code to try and attempt this:
byte[] fileBytes = System.IO.File.ReadAllBytes(@"server-name\folder1\folder2\file.xlsx");
return File(fileBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
If I log into the hosting server (using my personal Windows credentials), I'm able to access this location via File Explorer, so I know that the connection between the two is fine.
I've seen solutions related to impersonation, but from what I understand, that would require a central username/password. I just want the method that utilizes their own windows credentials.