本文介绍了ERR_CONNECTION_RESET:上传大文件时重置了连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个神秘的错误,大于4MB的文件会产生随机错误。后来我意识到这是由于
。默认情况下上传时,图片不能超过4MB。

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.

我知道这可以从web.config文件中改变。

I know that this can change from the web.config file.

当我试图迎合这个时错误,通过显示另一个页面,弹出一个不同的错误弹出。调试时,程序立即进入application_error。

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.

执行 Server.GetLastError()生成异常时:

堆栈跟踪:位于
System.Web.UI的System.Web.UI.Page.HandleError(例外e)处。 Page.ProcessRequestMain(布尔
includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)
在System.Web.UI.Page.ProcessRequest(布尔
includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)
在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。
c中的ProcessRequest(HttpContext上下文):\ Users \ Mattew \ App Data \ Local \Temp \Temporary ASP.NET
Files \root \ 4ea30077\8f66786f\App_Web_h5fmhavk.4.cs:$ 0
的System.Web.HttpApplication.CallHandlerExecutionStep。 System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)

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)

如果我在application_error方法中尝试任何代码,例如重定向,仍然是错误页面:
错误101(net :: ERR_CONNECTION_RESET):连接已重置。显示

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.

问题


  1. 如何处理此错误?可以事先处理吗?那么这个错误没有显示出来? (我尝试使用jquery来获取文件大小并检查它,但我发现它太复杂了

  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

如果问题1不是'回答',是有没有办法拦截这个错误并显示一个友好的错误?

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


推荐答案

试试这个。

在web.config中的系统网站下

Under system web in web.config

添加此行..

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

这篇关于ERR_CONNECTION_RESET:上传大文件时重置了连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 15:08