C# - Response.AddHeader Access Denied

CipherIS
CipherIS used Ask the Experts™
on
When I use the following code from the browser I get:

Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fi.Name));

I receive the following error.

Access to the path '\\myserver\mydir\myfile.txt' is denied.

When I run visual studio the file downloads without a problem.

Any ideas how to resolve?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Do you mean when you debug in visual studio, it works fine?  If so, it could about file rights.  When you host the page on iis, the default user is the asp.net user, which would likely wouldn't have rights to a file path that you've show, certainly, not by default.  It may be about giving windows file rights to the asp.net user so iis context user can access the file.

Author

Commented:
@AncientAnt - Yes when running visual studio the download works fine.  When I go to a browser and access the website I get "access is denied"
so the user that your iis server runs as, needs to have at a minimum, read rights sccess to '\\myserver\mydir\' on your server/pc.

I would guess that is the NETWORK SERVICE

 http://forums.asp.net/t/1013434.aspx/1 as posted by @indrajitmahajan explains this

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial