title: Fileupload large file size error handling
body: <p>My web.config setting is as below:</p>
  
  <pre><code>&lt;httpRuntime maxRequestLength="5000" executionTimeout="120"/&gt;
  </code></pre>
  
  <p>My error handling code in Global.asax:</p>
  
  <pre><code>void Application_Error(object sender, EventArgs e)
  {
      // Code that runs when an unhandled error occurs
      //Exception ex;
  
      string sourcepath = System.IO.Path.GetFileName(Request.Path);
      if (string.Compare(System.IO.Path.GetFileName(Request.Path), "vendorMassUpload.aspx", StringComparison.OrdinalIgnoreCase) == 0)
      {
          System.Exception lastException = Server.GetLastError();
          HttpException httpException = (HttpException)lastException;
          int httpCode = httpException.GetHttpCode();
          int errorCode = httpException.ErrorCode;
          if (errorCode == -2147467259)
          {
              Server.ClearError();
              Response.Redirect("~/vendorManagement/vendorMassUpload.aspx?fileTooLarge=true");
          }
      }
  }
  </code></pre>
  
  <p>The file size I use to upload in testing is 4999 KB.
  It will reach the <code>Response.Redirect</code> but it just show me <code>This page can’t be displayed</code> in Internet Explorer.</p>
  
  <p>If I <code>throw new Exception("testing exception");</code> in <code>ButtonUpload_Click</code> with <code>if (errorCode == -2147467259)</code> commented, everything just work.</p>
  
  <p>What went wrong?</p>
  
  <p>All I want to do is redirect user and show them custom message when they upload large file instead of telling them <code>This page can’t be displayed</code>.</p>