title: Redirect user to another page on Page_Error
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/6773346/maximum-request-length-exceeded-not-redirect-on-error-page">Maximum Request Length Exceeded Not Redirect on Error Page</a>  </p>
  </blockquote>
  
  
  
  <p>I try to redirect user to some error page, when he uploads file that exceed maximum size.  </p>
  
  <p>I've put in Web.config following line to limit file to 10MB:</p>
  
  <pre><code>&lt;httpRuntime maxRequestLength="10240" executionTimeout="360" /&gt;
  </code></pre>
  
  <p>On my page there's a simply form with standard ASP file upload control and submit button.
  I've also defined redirection on Page level (I've tried also in Global.asax Application_Error handling, but results are the same):</p>
  
  <pre><code>protected void Page_Error(object sender, EventArgs e)
  {
      if (HttpContext.Current.Error is HttpException)
      {
          if ((HttpContext.Current.Error as HttpException).ErrorCode==-2147467259)
          {
              Server.ClearError();
              Response.Redirect("~/Error.aspx");
          }
      }
  }
  </code></pre>
  
  <p>I've tried also <code>Server.Transfer()</code> - not working.</p>
  
  <p>When I try to upload file bigger than 10 MB I can debug and see that the code from <code>Page_Error</code> is being fully executed twice: even with <code>Server.ClearError()</code>, but the page is not redirected to <code>Error.aspx</code>. Instead, the standard, ugly "Connection has been reset" error page appears.</p>
  
  <p>This code works OK if the error is another type, like division by 0 set on <code>Page_Load</code>. Can you tell me what am I doing wrong here?</p>
  
  <p>BTW. I use Visual Web Developer 2010 Express with .NET 4.0, WindowsXP. Testing on buld-in to VWD IIS server.</p>