???????protected override void OnException(ExceptionContext filterContext) ???????{ ???????????// 此处进行异常记录,可以记录到数据库或文本,也可以使用其他日志记录组件。 ???????????// 通过filterContext.Exception来获取这个异常。 ???????????filterContext.ExceptionHandled = true;//组织web.config配置customerror处理 ???????????string requestType = filterContext.HttpContext.Request.RequestType.ToString();//获取请求类型 ???????????UrlHelper url = new UrlHelper(filterContext.RequestContext); ???????????//判断是否为get请求,如果为get请求,跳转指定页面,如果不是返回json ???????????if (requestType.ToUpper() == "GET") ???????????{ ???????????????filterContext.Result = new RedirectResult(url.Action("error", "Error"));//跳转到新页面 ???????????} ???????????else ???????????{ ???????????????filterContext.Result = new JsonResult() { Data = new { errorcode = 2, message = filterContext.Exception.Message }, JsonRequestBehavior = JsonRequestBehavior.AllowGet };//返回json数据 ???????????} ???????????// 执行基类中的OnException ???????????//base.OnException(filterContext); ???????}
asp.net ?重写OnException返回json或跳转新页面
原文地址:http://www.cnblogs.com/Chavezcn/p/7580624.html