2

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?

1
  • Are you testing this in your LocalHost? If you are it seems like an ASPNET user account issue. Try and see if you have permission to write/read in this folder with this account. Commented Dec 10, 2012 at 22:52

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

We can't do impersonation in general, since this is a very large preexisting commerce website...the testing for a global change would be prohibitive. But it does make me think that I might be able to just drop this functionality into it's own directory, and put a local web.config in that directory, and do impersonation there. (I can't try this right now unfortunately...but when I can, I'll report on results.) I'll also look at your first option when I can (probably early tomorrow.) Thanks for the pointers.
Thanks for the options. The 2nd option was what worked for me (impersonating a user, specifically created for this access, and putting that into a web.config in a directory with only that file), but the other options sound like good options that might work for other people with a similar issue.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.