0

私は次のコードを持っています

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();                
}

破損したファイルであっても、ファイルはクライアント用にダウンロードされますが、ファイルのダウンロードを停止する方法はあります。

4

2 に答える 2

1
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")
}
于 2012-11-07T14:09:40.850 に答える
0

UnauthorizedAccessException をキャッチしているので、関連する HTTP ステータス コード (つまり 401) で HttpException をスローしない理由 -

throw new HttpException(401, ex.Message);
于 2012-11-07T14:25:02.360 に答える