问题描述
我跟着这些链接:
-
和 - 在当前显示错误页面
- Catching "Maximum request length exceeded"and
- ASP.NET - how to show a error page when uploading big file (Maximum request length exceeded)?
显示错误页面来处理上传文件超过了的maxRequestLength
在的web.config
to display error page to handle uploading files exceeding the maxRequestLength
in web.config
但我的问题是,它不是重定向到错误页面(有消息称,该网页无法显示)。我不知道我错过了什么。
But my problem is, it is not redirected to the error page (the message says that the webpage cannot be displayed ). I do not know what I'm missing.
下面是我的code @ 的Global.asax
:
Here's my Code @ Global.asax
:
void Application_Error(object sender, EventArgs e)
{
if (IsMaxRequestLengthExceeded(Server.GetLastError()))
{
this.Server.ClearError();
this.Server.Transfer("~/Error.html");
}
}
private bool IsMaxRequestLengthExceeded(Exception ex)
{
Exception main;
HttpUnhandledException unhandledEx = (HttpUnhandledException)ex;
if (unhandledEx != null && unhandledEx.ErrorCode == -2147467259)
{
main = unhandledEx.InnerException;
}
else
{
main = unhandledEx;
}
HttpException httpException = (HttpException)main;
if (httpException != null && httpException.ErrorCode == -2147467259)
{
if (httpException.StackTrace.Contains("GetEntireRawContent"))
{
return true;
}
}
return false;
}
和@ 的web.config
:
<httpRuntime executionTimeout="1200" />
<customErrors defaultRedirect="Error.html" mode="On">
</customErrors>
据发现,当的maxRequestLength
未初始化,它的默认设置为4MB。 (我没有设置它,因为它是不是对我很重要。)
It found out that when maxRequestLength
was not initialized, it is set by default to 4MB. (I didn't set it because it is not important to me.)
希望你能帮助我。谢谢
推荐答案
我能找到另一种方式来解决的maxRequestLength
错误。我发现它在此链接:
I was able to find another way to solve maxRequestLength
error. I found it in this link:
该解决方案被张贴由拉克什·库马尔·罗伊(帖子详细信息:周五,2009年2月13日下午1:43)发表评论。这可能是其他程序员很有帮助那里。 :D
The solution was posted as comment by Rakesh Kumar Roy (Post Details: Friday, February 13, 2009 1:43 PM). This might be helpful for other programmers out there. :D
这篇关于超过最大请求长度上的错误页面重定向不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!