clickclickbang
asked on
Capture Maximum request length exceeded Exception
I am creating a page to accept user files. During testing I received a Maximum request length exceeded error. The fix to this (http://www.powupload.com/System.Web.HttpException-Maximum-request-length-exceeded.aspx) is to up your MaxRequestLength property. However, is there a way to capture this exception before it is thrown? I attempted to wrap the upload file's SaveAs() method in a try/catch but it did not catch the exception.
How do I capture this exception so when a user does exceed the max limit I can alert them accordingly.
How do I capture this exception so when a user does exceed the max limit I can alert them accordingly.
ASKER
Not much to it really...
protected void UploadFile_Click(object sender, EventArgs e)
{
string UploadDir = Server.MapPath(WebConfigur ationManag er.AppSett ings["Imag eHandler_T empDir"]);
try
{
FileUpload1.SaveAs(UploadD ir + Path.GetFileName(FileUploa d1.FileNam e));
}
catch (System.Web.HttpException ex)
{
throw new Exception("I Got You");
}
catch (Exception ex)
{
throw new Exception("I Got You");
}
}
Still throws "Maximum request length exceeded. "
I assume you'd need to catch it else where. I tried :
protected override void OnLoad(EventArgs e)
{
try
{
base.OnLoad(e);
}
catch (System.Web.HttpException ex)
{
throw new Exception("I Got You");
}
catch (Exception ex)
{
throw new Exception("I Got You");
}
}
But figured I'd see if any EE Genius knows where or how.
protected void UploadFile_Click(object sender, EventArgs e)
{
string UploadDir = Server.MapPath(WebConfigur
try
{
FileUpload1.SaveAs(UploadD
}
catch (System.Web.HttpException ex)
{
throw new Exception("I Got You");
}
catch (Exception ex)
{
throw new Exception("I Got You");
}
}
Still throws "Maximum request length exceeded. "
I assume you'd need to catch it else where. I tried :
protected override void OnLoad(EventArgs e)
{
try
{
base.OnLoad(e);
}
catch (System.Web.HttpException ex)
{
throw new Exception("I Got You");
}
catch (Exception ex)
{
throw new Exception("I Got You");
}
}
But figured I'd see if any EE Genius knows where or how.
ASKER
Any ideas on this? If I can't catch this error, how else can I handle a user that attempts to upload a 20MB image?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks for your post!
Andrew :-)