我有以下代码
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();
}
该文件仍会为客户端下载,尽管文件已损坏,但有办法阻止文件下载。