文章内容
2017/6/12 11:30:56,作 者: 黄兵
asp.net mvc log4net错误页面冲突,重定向次数过多
最近用log4net 截获网站错误的时候,看了一下数据库,错误还正是多。一天之内就有100多条。

慢慢的修复存在的错误,但是当错误跳转到Error页面的时候提示“重定向次数过多”,如图所示:

我想起来了,ExceptionFileAttribute这个属性也重定向了错误(Error)页面,但是web.config也重定向了Error页面。
代码如下:
using System.Web.Mvc;using MyBlog.Extensions;namespace MyBlog.App_Start{public class ExceptionFileAttribute : HandleErrorAttribute{public override void OnException(ExceptionContext filterContext){base.OnException(filterContext);//处理错误消息,将其跳转到一个页面LogHelper.WriteLog(filterContext.Exception.ToString());//页面跳转到错误页面filterContext.HttpContext.Response.Redirect("Error");}}}
web.config配置错误页面如下:
<customErrors mode="On" defaultRedirect="Error"><error statusCode="404" redirect="/Home/System_notfound"/></customErrors>
解决办法:
删除ExceptionFileAttribute重定向的Error页面,如下所示:
using System.Web.Mvc;using MyBlog.Extensions;namespace MyBlog.App_Start{public class ExceptionFileAttribute : HandleErrorAttribute{public override void OnException(ExceptionContext filterContext){base.OnException(filterContext);//处理错误消息,将其跳转到一个页面LogHelper.WriteLog(filterContext.Exception.ToString());//页面跳转到错误页面//filterContext.HttpContext.Response.Redirect("Error");}}}
最后测试,Error页面跳转正常。
黄兵的个人博客原创。
评论列表