本文介绍了异常“超出最大请求长度”时,Application_Error不会从Global.asax重定向到错误页面。被提出来了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在使用Visual Studio 2010 / ASP.NET / C-Sharp网站。 我基本上有一个ASP.NET FileUpload控件,我需要它满足以下消息抛出的异常: - 超出最大请求长度。 最大文件大小设置在Web中设置。配置如下: - < system.webServer > < 安全性 > < requestFiltering > < requestLimits maxAllowedContentLength = 41943040 / > < / requestFiltering > < / security > < / system.webServer > 和 < system.web > < httpRuntime maxRequestLength = 40960 requestValidationMode = 2.0 / > < / system.web > 在Application_Error()中使用Global.asax验证文件大小,但它没有解决我的问题,当文件大小更大并且重定向到错误页面不起作用时,它在重定向时崩溃。 我使用了以下代码,虽然它现在正在运行Application_Error()代码部分,但问题是它没有重定向到About.aspx页面。 void Application_Error( object sender, EventArgs e) { // 发生未处理错误时运行的代码 Exception exc = Server.GetLastError(); 尝试 { if (exc.Message.Contains( 超出最大请求长度)) { Response.Redirect( 〜/ About.aspx, false ); } if (exc.InnerException.Message.Contains( 超出最大请求长度)) { Response.Redirect( 〜/ About.aspx, false ); } } catch (例外情况) { } } 我想知道如何才能达到我的要求,因为我几天后就被困住了。 请尽早帮助我。解决方案 您必须在重定向之前清除错误对象。 ie HttpContext.Current.ClearError(); Response.Redirect( 〜/ About.aspx,假); I am using Visual Studio 2010/ASP.NET/C-Sharp website.I basically had an ASP.NET FileUpload control, for which I needed to cater the exception thrown for the following message:-Maximum request length exceeded.The maximum file size setting is set in the web.config as follows:-<system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="41943040"/> </requestFiltering> </security></system.webServer>And<system.web> <httpRuntime maxRequestLength="40960" requestValidationMode="2.0" /></system.web>Using Global.asax with validating file size in "Application_Error()", but it has not resolved my issue and it crashes at the Redirect when file size is greater and a redirect to Error Page is not working.I have used the following code, although it is now running the Application_Error() Code section, but the problem is that it is not redirecting to the About.aspx page.void Application_Error(object sender, EventArgs e) { // Code that runs when an unhandled error occurs Exception exc = Server.GetLastError(); try { if (exc.Message.Contains("Maximum request length exceeded")) { Response.Redirect("~/About.aspx", false); } if (exc.InnerException.Message.Contains("Maximum request length exceeded")) { Response.Redirect("~/About.aspx", false); } } catch (Exception ex) { } }I want to find out that how can I accomplish my requirements, since I am stuck for this since a couple of days.Kindly help me in this regards as early as possible. 解决方案 You have to clear the error object before the redirect.i.e.HttpContext.Current.ClearError();Response.Redirect("~/About.aspx", false); 这篇关于异常“超出最大请求长度”时,Application_Error不会从Global.asax重定向到错误页面。被提出来了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-14 19:27