栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

捕捉到“超出最大请求长度”

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

捕捉到“超出最大请求长度”

不幸的是,没有简单的方法来捕获此类异常。我要做的是要么在页面级别覆盖OnError方法,要么在global.asax中覆盖Application_Error,然后检查它是否是最大请求失败,如果是,则转移到错误页面。

protected override void onError(EventArgs e) .....private void Application_Error(object sender, EventArgs e){    if (GlobalHelper.IsMaxRequestExceededException(this.Server.GetLastError()))    {        this.Server.ClearError();        this.Server.Transfer("~/error/UploadTooLarge.aspx");    }}

这是一个hack,但是下面的代码对我有用

const int TimedOutExceptionCode = -2147467259;public static bool IsMaxRequestExceededException(Exception e){    // unhandled errors = caught at global.ascx level    // http exception = caught at page level    Exception main;    var unhandled = e as HttpUnhandledException;    if (unhandled != null && unhandled.ErrorCode == TimedOutExceptionCode)    {        main = unhandled.InnerException;    }    else    {        main = e;    }    var http = main as HttpException;    if (http != null && http.ErrorCode == TimedOutExceptionCode)    {        // hack: no real method of identifying if the error is max request exceeded as         // it is treated as a timeout exception        if (http.StackTrace.Contains("GetEntireRawContent"))        { // MAX REQUEST HAS BEEN EXCEEDED return true;        }    }    return false;}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/402874.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号