我跟着這些鏈接:超過最大請求長度不上的錯誤頁面重定向
- Catching "Maximum request length exceeded" 和
- ASP.NET - how to show a error page when uploading big file (Maximum request length exceeded)?
在web.config
maxRequestLength
但我的問題是,它沒有重定向到錯誤p年齡(該消息表示該網頁無法顯示)。我不知道我錯過了什麼。
這裏是我的代碼@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。 (我沒有設置它,因爲它對我來說並不重要。)
希望你能幫助我解決這個問題。謝謝
不應該 「的error.html」 在web.config中與Global.asax中的「〜/ Error.html」相同? –
嗨,使用'Error.html'導致錯誤,我需要'〜'字符來指定虛擬目錄的根路徑。 – KaeL
不應該在兩個地方都是「〜/ Error.html」(web.config也是)? –