Click here to Skip to main content
15,940,921 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I created a project with an aspx page + an ashx file.  This process consists of 2 steps:
1) After clicking the button in the aspx page (http://localhost/default.aspx), it directs to the ashx.
2) When the ashx file is called, a generated file will save into a desired local folder.
This process works well when I run debugging.  However, after I deploy it into IIS, Step 2) does not function, and it directs to our server's error.html.
What's the possible problem for this failure?  Is it fialure due to the IIS setting?  Thanks. 

What I have tried:

Error in directing to an Ashx after deployed
Updated 1-Jun-20 23:52pm
MadMyche 1-Jun-20 17:41pm    
Are you logging the exceptions on the server?

1 solution

When the ashx file is called, a generated file will save into a desired local folder.
Your ASHX code is running on the server. You are trying to save the file to a folder on the server. It's quite likely that the folder either doesn't exist, or your application doesn't have permission to write to it.

If you want the file to be saved on the user's computer, you need to send the file in the response with the appropriate headers.
Downloading a File with a Save As Dialog in ASP.NET - Rick Strahl's Web Log[^]

NB: Before you ask, no, you cannot force the user to save the file in a particular folder, or with a particular name. You cannot even force them to save it; they could chose to open it instead, or to abort the download.
Share this answer
s yu 2-Jun-20 7:50am    
Actually, I try to save the file into C:\Temp\ (it exists) rather than into a Server folder.
Richard Deeming 2-Jun-20 7:51am    
As I said, your code is running on the server.

Code running on the server has no access to the user's file system.

You need to send the file in the response, as per the link in my answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900