首页 > 代码库 > MVC 好记星不如烂笔头之 ---> 全局异常捕获以及ACTION捕获
MVC 好记星不如烂笔头之 ---> 全局异常捕获以及ACTION捕获
public class BaseController : Controller { /// <summary> /// Called after the action method is invoked. /// </summary> /// <param name="filterContext">Information about the current request and action.</param> protected override void OnActionExecuted(ActionExecutedContext filterContext) { var servicename = string.Empty; foreach (var value in filterContext.RequestContext.RouteData.Values) { if (value.Key.ToLower() == "controller") //获取当前的Controller { servicename += value.Value.ToString() + "---"; } else if (value.Key.ToLower() == "action")//获取当前的ActionName { servicename += value.Value.ToString(); } } LogWriter.Debug(servicename); base.OnActionExecuted(filterContext); } /// <summary> /// Called when an unhandled exception occurs in the action. /// </summary> /// <param name="filterContext">Information about the current request and action.</param> protected override void OnException(ExceptionContext filterContext) { LogWriter.Error(filterContext.Exception.Message, filterContext.Exception); //全局异常捕获输出 base.OnException(filterContext); } }
MVC 好记星不如烂笔头之 ---> 全局异常捕获以及ACTION捕获
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。