ERR_CONNECTION_RESET: The connection was reset when uploading a large file

倾然丶 夕夏残阳落幕 提交于 2019-12-10 02:56:39

问题


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

  1. 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

  2. If Question 1 is not 'answerable', is there a way to intercept this error and display a friendly error?


回答1:


Try this out.

Under system web in web.config

add this line..

  <system.web>
<httpRuntime executionTimeout="999" maxRequestLength="2097151"/>

Then you need to check the file size

if (AsyncFileUpload1.HasFile)
        {
            string FileName = Path.GetFileName(AsyncFileUpload1.PostedFile.FileName);
            string Extension = Path.GetExtension(AsyncFileUpload1.PostedFile.FileName);
            string FolderPath = ConfigurationManager.AppSettings["FolderPath"];
            string FilePath = Server.MapPath("~/xl/" + FileName);
            double filesize = (double)AsyncFileUpload1.FileBytes.Length;
            if (filesize < 106496)
            {
               //do something
            }
            else
            {
                Response.Write("File size must be less than 2MB.");
            }

If you find it useful, please mark it as your answer else let me know..



来源:https://stackoverflow.com/questions/8129362/err-connection-reset-the-connection-was-reset-when-uploading-a-large-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!