Possible Duplicate:
Maximum Request Length Exceeded Not Redirect on Error Page
I try to redirect user to some error page, when he uploads file that exceed maximum size.
I've put in Web.config following line to limit file to 10MB:
<httpRuntime maxRequestLength="10240" executionTimeout="360" />
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):
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");
}
}
}
I've tried also Server.Transfer() - not working.
When I try to upload file bigger than 10 MB I can debug and see that the code from Page_Error is being fully executed twice: even with Server.ClearError(), but the page is not redirected to Error.aspx. Instead, the standard, ugly "Connection has been reset" error page appears.
This code works OK if the error is another type, like division by 0 set on Page_Load. Can you tell me what am I doing wrong here?
BTW. I use Visual Web Developer 2010 Express with .NET 4.0, WindowsXP. Testing on buld-in to VWD IIS server.