Avatar of CipherIS
CipherIS
Flag for United States of America asked on

C# - Response.AddHeader Access Denied

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?
ASP.NETC#.NET Programming

Avatar of undefined
Last Comment
AncientAnt

8/22/2022 - Mon
AncientAnt

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.
SOLUTION
Indrajit Mahajan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
CipherIS

ASKER
@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"
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck