ERR_CONNECTION_RESET:上传大文件时连接被重置

发布于 2024-12-15 06:17:26 字数 1606 浏览 0 评论 0原文

我遇到了一个神秘错误,大于 4MB 的文件生成了随机错误。后来我意识到这是由于 http 引起的最大请求长度 。默认上传的图片不能大于4MB。

我知道这可以通过 web.config 文件进行更改。

当我尝试通过显示另一个页面来解决此错误时,开始弹出一个不同的错误。调试时,程序立即进入application_error。

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

[System.Web.HttpUnhandledException] {“异常类型 “System.Web.HttpUnhandledException”是 抛出。”} System.Web.HttpUnhandledException

堆栈跟踪:位于 System.Web.UI.Page.HandleError(Exception e) 处 System.Web.UI.Page.ProcessRequestMain(布尔值 includeStagesBeforeAsyncPoint、布尔值 includeStagesAfterAsyncPoint) 在 System.Web.UI.Page.ProcessRequest(布尔值 includeStagesBeforeAsyncPoint、布尔值 includeStagesAfterAsyncPoint) 在 System.Web.UI.Page.ProcessRequest() 处 System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext 上下文)位于 System.Web.UI.Page.ProcessRequest(HttpContext上下文)位于 ASP.businessprofile_aspx.ProcessRequest(HttpContext 上下文) 中 c:\Users\Mattew\AppData\Local\Temp\Temporary ASP.NET 文件\root\4ea30077\8f66786f\App_Web_h5fmhavk.4.cs:第 0 行 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 在 System.Web.HttpApplication.ExecuteStep(IExecutionStep 步骤, 布尔&同步完成)

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

问题

  1. 应该如何处理此错误?可以提前处理吗?那么这个错误不显示吗? ( 我之前尝试过使用jquery获取文件大小并检查它,但我发现它太复杂了

  2. 如果问题 1 无法“回答”,有没有办法拦截此错误并显示友好错误?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟燃烟灭 2024-12-22 06:17:27

试试这个。

在 web.config 中的系统 web 下

添加此行..

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

然后您需要检查文件大小

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.");
            }

如果您发现它有用,请将其标记为您的答案,否则请告诉我..

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文