public class EwHandleErrorAttribute : HandleErrorAttribute
{
public override void OnException(ExceptionContext filterContext)
{
if (ICTConfiguration.Debug)
{
base.OnException(filterContext);
return;
} if (filterContext.ExceptionHandled)
{
return;
}
if (filterContext.HttpContext.Response.IsRequestBeingRedirected)
{
return;
}
var httpCode = new HttpException(null, filterContext.Exception).GetHttpCode();
if (!ExceptionType.IsInstanceOfType(filterContext.Exception))
{
return;
}
if (new HttpException(null, filterContext.Exception).GetHttpCode() != )
{
return;
}
ExceptionHelper.LogException(filterContext.Exception, HttpContext.Current);
bool isAjaxCall = string.Equals("XMLHttpRequest", filterContext.HttpContext.Request.Headers["x-requested-with"],
StringComparison.OrdinalIgnoreCase);
if (isAjaxCall)
{
string message = filterContext.Exception.Message;
if (filterContext.Exception is HttpRequestValidationException)
{
message = "包含非法字符";
} filterContext.Result = new JsonResult()
{
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
Data = new
{
succeed = false,
ret = httpCode,
msg = message
}
};
}
else
{
var controllerName = (string)filterContext.RouteData.Values["controller"];
var actionName = (string)filterContext.RouteData.Values["action"];
var model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);
filterContext.Result = new ViewResult()
{
ViewName = View,
MasterName = Master,
ViewData = new ViewDataDictionary(model),
TempData = filterContext.Controller.TempData
};
filterContext.HttpContext.Response.Redirect("/500.html");
}
filterContext.ExceptionHandled = true;
filterContext.HttpContext.Response.Clear();
filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
filterContext.HttpContext.Server.ClearError();
}
}

global注册过滤器

 public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new JoinEnterpriseAttribute(), );
filters.Add(new EwHandleErrorAttribute(), );
}

HandleErrorAttribute 特性使用的更多相关文章

  1. 【转载】MVC使用HandleErrorAttribute自定义异常

    本文导读:在ASP.NET MVC中,可以使用HandleErrorAttribute特性来具体指定如何处理Action抛出的异常.只要某个Action设置了HandleErrorAttribute特 ...

  2. MVC使用HandleErrorAttribute自定义异常

    MVC中,有一个Filter可以捕捉错误,但是它的用法是利用Attribute来实现的,而且只能加在Controller和Action上,所以不能捕捉别出的错误 其实理论上所有的错误肯定产生于Cont ...

  3. 在ASP.NET Core使用Middleware模拟Custom Error Page功能

    一.使用场景 在传统的ASP.NET MVC中,我们可以使用HandleErrorAttribute特性来具体指定如何处理Action抛出的异常.只要某个Action设置了HandleErrorAtt ...

  4. 在MVC中处理异常的总结

    无论是桌面程序还是web程序,异常处理都是必须的. 一般的处理方式是, 捕获异常,然后记录异常的详细信息到文本文件或者数据库中.在Asp.net MVC中可以使用内建的filter——HandleEr ...

  5. ASP.net MVC自定义错误处理页面的方法

    在ASP.NET MVC中,我们可以使用HandleErrorAttribute特性来具体指定如何处理Action抛出的异常.只要某个Action设置了HandleErrorAttribute特性,那 ...

  6. ASP.NET MVC 过滤器开发与使用

    ASP.NET MVC 中给我们提供了内置的过滤器,通过过滤器,我们可以在控制器内的方法前后,添加必须的业务逻辑,如权限验证,身份验证,错误处理等. 今天,我们主要介绍3个过滤器:OutputCach ...

  7. ASP.NET MVC编程——错误处理与日记

    ASP.NET MVC的错误处理应考虑到这几个方面:模型绑定期间发生的错误,未能路由到指定操作,针对控制器的错误处理.使用配置文件可以帮助我们处理异常,但是不够灵活和全面:使用HandleErrorA ...

  8. .NET MVC自定义错误处理页面的方法

    在ASP.NET MVC中,我们可以使用HandleErrorAttribute特性来具体指定如何处理Action抛出的异常.只要某个Action设置了HandleErrorAttribute特性,那 ...

  9. vue前端开发那些事——后端接口.net core web api

    红花还得绿叶陪衬.vue前端开发离不开数据,这数据正来源于请求web api.为什么采用.net core web api呢?因为考虑到跨平台部署的问题.即使眼下部署到window平台,那以后也可以部 ...

随机推荐

  1. maven的聚合与继承5

    一.聚合 如果我们想一次构建多个项目模块,那我们就需要对多个项目模块进行聚合 1.1.聚合配置代码 1 <modules> 2 <module>模块一</module&g ...

  2. 一次tomcat服务器被入侵解决办法

    突然tomcat目录下莫名其妙的多了几个war文件,里面内容只有一个index.jsp,打开控制台发现多了几个应用,我可以确定不是我部署上去的,顺着应用访问竟然看到了

  3. (二)再议MII、RMII、GMII接口

    概述:         MII (Media Independent Interface(介质无关接口)或称为媒体独立接口,它是IEEE-802.3定义的以太网行业标准.它包括一个数据接口和一个MAC ...

  4. hostapd源代码分析(一):网络接口和BSS的初始化

    [转]hostapd源代码分析(一):网络接口和BSS的初始化 原文链接:http://blog.csdn.net/qq_21949217/article/details/46004349 最近在做一 ...

  5. iOS开发之Xcode 6 国际化

    Xcode6 国际化 (1) 新建一个Single View app模版项目,命名为LocalizationTest 1.建立strings文件,命名为Localization.strings 2.点 ...

  6. BestCoder Valentine's Day Round

    昨晚在开赛前5分钟注册的,然后比赛刚开始就掉线我就不想说了(蹭网的下场……),只好用手机来看题和提交,代码用电脑打好再拉进手机的(是在傻傻地用手机打了一半后才想到的办法). 1001,也就是 hdu ...

  7. vim 学习记录

    VIM中PHP代码使用tab键自动完成 更新于 2013-01-18 05:47:55UEANER 目录结构 $ tree -C ~/.vim | grep -v ".cnx" | ...

  8. 谱聚类Ng算法的Matlab简单实现

    请编写一个谱聚类算法,实现"Normalized Spectral Clustering-Algorithm 3 (Ng 算法)" 结果如下 谱聚类算法核心步骤都是相同的: •利用 ...

  9. K均值聚类(Kmeans)

    Sigma = [1, 0; 0, 1]; mu1 = [1, -1]; x1 = mvnrnd(mu1, Sigma, 200); mu2 = [5.5, -4.5]; x2 = mvnrnd(mu ...

  10. phalcon: Windows 下 Phalcon dev-tools 配置 和 Phpstorm中配置Phalcon 代码提示, phalcon tools的使用

    准备: phalcon-devtools包 下载地址: https://github.com/phalcon/phalcon-devtools 解压到wampserver的www目录 (xampp 用 ...