I had a mysterious error where a file greater than 4MB generated a random error. Later on I realized it was caused due to the http maxrequestlength
. An image cannot be greater than 4MB when uploaded by default.
I know that this can change from the web.config file.
When I tried to cater for this error, by displaying another page, a different error started popping up. When debugging, the program enters application_error immediately.
When executing Server.GetLastError()
Exception generated:
[System.Web.HttpUnhandledException] {"Exception of type 'System.Web.HttpUnhandledException' was thrown."} System.Web.HttpUnhandledException
the stack trace: at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.businessprofile_aspx.ProcessRequest(HttpContext context) in c:\Users\Mattew\AppData\Local\Temp\Temporary ASP.NET Files\root\4ea30077\8f66786f\App_Web_h5fmhavk.4.cs:line 0 at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
If I try any code inside the application_error method, e.g. redirecting, still the error page: Error 101 (net::ERR_CONNECTION_RESET): The connection was reset. is displayed.
Questions
How should this error be handled? Can it be handled before hand? So this error is not displayed? ( I tried using jquery to get the file size before and check it but I'm finding it too complex
If Question 1 is not 'answerable', is there a way to intercept this error and display a friendly error?
Try this out.
Under system web in web.config
add this line..
Then you need to check the file size
If you find it useful, please mark it as your answer else let me know..