开发者

I'm trying to catch and clear an error in ASP.net but I get redirected to "The connection to the server was reset while the page was loading"

开发者 https://www.devze.com 2022-12-12 17:23 出处:网络
I\'ve got a page that lets you upload files. I\'ve increased the maximum filesize to the desired level and that works but I would like to have customised error handling for when the user uploads somet

I've got a page that lets you upload files. I've increased the maximum filesize to the desired level and that works but I would like to have customised error handling for when the user uploads something too big.

All the guides I've found so far give advice on how to redirect to a specal error page, I can't find anything on how to just present the error in a current page. Here's what I'm using so far.

protected override void OnError(EventArgs e)
{
    HttpContext hcCurrentContext = HttpContext.Current;

    Exception eException = this.Server.GetLastError();

    if (eException.Message.Equals("Maximum request length exceeded."))
    {
        hcCurrentContex开发者_如何学运维t.Server.ClearError();
        tbErrorMessage.Text = "File too large";
        tbErrorMessage.Visible = true;
    }
    else
    {
        base.OnError(e);
    }
}

I ran it through a debugger and it does go into the If clause correctly, but I still get redirected to the default FireFox error page with the message "The connection to the server was reset while the page was loading". Can anyone advise me?


Trapping exceptions that arise when large files are uploaded is hard, as there are inbuilt checks in IIS to prevent denial-of-service attacks that cause these exceptions to be generated.

See Jon Galloway's post for details on how to get around this. In essence you'll need to

  • Attempt reconfiguration of IIS to handle larger files
  • Try an third-party component that allows larger files
  • Trap HTTP 400 in IIS - which isn't ideal, as the 400 code can happen in other circumstances.
0

精彩评论

暂无评论...
验证码 换一张
取 消