Reputation: 8285
I have the following code
try
{
GetFileAndDisplay() // Gets the file from the server and writes the file in a Response stream
}
catch (UnauthorizedAccessException ex)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Msg", "<script type='text/javascript'>alert('Error')</script>");
Response.Clear();
Response.ContentType = "";
Response.End();
}
The file still gets downloaded for the client, albeit a corrupted file but is there a way to stop the file from downloading.
Upvotes: 0
Views: 180
Reputation: 2344
As you are catching an UnauthorizedAccessException why not throw a HttpException with a relevant HTTP status code (i.e a 401) -
throw new HttpException(401, ex.Message);
Upvotes: 0
Reputation: 10544
try
{
GetFileAndDisplay() // Gets the file from the server and writes the file in a Response stream
}
catch (UnauthorizedAccessException ex)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Msg", "<script type='text/javascript'>alert('Error')</script>");
Response.Clear();
Response.Redirect("path/to/some/page/that/tells/the/user/something/is/wrong")
}
Upvotes: 1