首页 新闻 会员 周边

如何处理HttpException?

0
悬赏园豆:15 [已关闭问题]

Exception information:
    Exception type: HttpException
    Exception message: Maximum request length exceeded.
   at System.Web.HttpRequest.GetEntireRawContent()
   at System.Web.HttpRequest.GetMultipartContent()
   at System.Web.HttpRequest.FillInFormCollection()
   at System.Web.HttpRequest.get_Form()
   at System.Web.HttpRequest.get_HasForm()
   at System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull)
   at System.Web.UI.Page.DeterminePostBackMode()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

我知道这个exception是由于上传的文件大于config里面设置的maxRequestLength的时候抛出的。

但能不能在哪个地方控制,当遇到这个异常时跳转到另一个较为友好一点的URL,而不是 "Internet Explorer cannot display the webpage"?

Everlonely的主页 Everlonely | 初学一级 | 园豆:115
提问于:2010-06-22 09:19
< >
分享
其他回答(2)
0

在功能代码(函数)执行处控制,如:

代码
private void UpLoadFile()
{
try
{
// 上传操作
......
}
catch (Exception e)
{
// 转向其它预定义错误页面
if (e.Message == "Maximum request length exceeded")
Response.Redirect(
"error01.aspx");

// 或者弹出提示
//Page.ClientScript.RegisterStartupScript(this.GetType(), "haha", "<script>alert('" + e.Message + "')</script>");
}
}
哈欠懒农 | 园豆:455 (菜鸟二级) | 2010-06-22 09:38
这是不行的,因为lifecycle还没到这里,exception就已经throw出来,甚至不会执行这个try里面的内容。
支持(0) 反对(0) Everlonely | 园豆:115 (初学一级) | 2010-06-22 17:52
0

web.config设置错误转向。

Astar | 园豆:40805 (高人七级) | 2010-06-22 09:50
我试过配置,但事实证明这是不行的。。。
支持(0) 反对(0) Everlonely | 园豆:115 (初学一级) | 2010-06-22 17:53
0

在页面里写Page_error事件,在这个事件里重新定向到一个页面

protected void Page_Error(object sender, EventArgs e)
{
Response.Redirect(
"~/Error.html");
}

 

或者是Global.asax里的Application_error,代码同Page_error

kyo-yo | 园豆:5587 (大侠五级) | 2010-06-29 17:28
试过了,不行的
支持(0) 反对(0) Everlonely | 园豆:115 (初学一级) | 2010-07-05 01:10
Application_error都不能捕获?
支持(0) 反对(0) kyo-yo | 园豆:5587 (大侠五级) | 2010-07-06 14:27
@顾磊(kyo-yo):可以捕获,但无济于事。you can have a try
支持(0) 反对(0) Everlonely | 园豆:115 (初学一级) | 2010-07-07 09:46
既然可以捕获那就在这边进行跳转到指定的做错误页面不就好了么?
支持(0) 反对(0) kyo-yo | 园豆:5587 (大侠五级) | 2010-07-07 14:26
你可以試一下。
支持(0) 反对(0) Everlonely | 园豆:115 (初学一级) | 2010-07-08 13:36
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册