Avatar of CipherIS
CipherISFlag 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
Avatar of AncientAnt
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
Avatar of Indrajit Mahajan
Indrajit Mahajan
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of CipherIS
CipherIS
Flag of United States of America image

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
Avatar of AncientAnt
AncientAnt

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo