tl;dr: critical bits are in bold.
We have a website page that, when executed, is supposed to read in a series of files, zip them up, and return them to the user.
Unfortunately, we are running into an error:
ASP.NET is not authorized to access the requested resource. Consider
granting access rights to the resource to the ASP.NET request
identity. ASP.NET has a base process identity (typically
{MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if
the application is not impersonating. If the application is
impersonating via , the identity will be
the anonymous user (typically IUSR_MACHINENAME) or the authenticated
request user.
My line attempting to access the file currently looks like this:
using (FileStream x = File.Open(@"\\thedirectory\filename.pdf", FileMode.Open, FileAccess.Read)) { }
(This line doesn’t do anything useful other than try to open the file, since right now I’m just trying to see if I have access at all.)
This code works, and opens the file without a problem if I copy the file to a directory on my machine and have the path go there. But if I go to the remote machine where the original file is, no dice.
I went down a rabbit hole for a while trying to make sure that whoever the ASP.NET process was running as, that process had permissions to the directory. However, since that wasn’t working and I was getting desperate, I have given “everyone” all access rights to the remote directory as a test. Still getting the same error.
I’m guessing this is a permissions issue (since that’s what it’s claiming) combined with the fact that the code works when pointing at a local file. However, since I’ve already given “everyone” all permissions, I’m lost as to what could be going wrong.
Ideas?
I’m guessing that the other files are on a different machine, here is one possiblity: https://serverfault.com/questions/41130/network-service-account-accessing-a-folder-share
Another possiblity is to impersonate a domain account that has access to the target folder- http://support.microsoft.com/kb/306158
Or change the service account to a domain account that has access to the target folder.