本文整理汇总了C#中System.Web.Mvc.ExceptionContext.GetController方法的典型用法代码示例。如果您正苦于以下问题:C# ExceptionContext.GetController方法的具体用法?C# ExceptionContext.GetController怎么用?C# ExceptionContext.GetController使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.ExceptionContext
的用法示例。
在下文中一共展示了ExceptionContext.GetController方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnException
public override void OnException(ExceptionContext filterContext)
{
if (filterContext.ExceptionHandled) return;
if (new HttpException(null, filterContext.Exception).GetHttpCode() != 500) return;
if (!ExceptionType.IsInstanceOfType(filterContext.Exception)) return;
string controllerName = filterContext.GetController();
string actionName = filterContext.GetAction();
HandleErrorInfo model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);
filterContext.Result = new ViewResult
{
ViewName = View,
MasterName = Master,
ViewData = new ViewDataDictionary<HandleErrorInfo>(model)
};
//使用log4net写入本地日志
_logger.Error(filterContext.Exception.Message, filterContext.Exception);
filterContext.HttpContext.Response.Clear();
filterContext.HttpContext.Response.StatusCode = 500;
filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
filterContext.ExceptionHandled = true;
}
示例2: OnException
public void OnException(ExceptionContext filterContext)
{
StringBuilder strBuilder = new StringBuilder("异常信息:\r\n");
string controllerName = filterContext.GetController();
string actionName = filterContext.GetAction();
strBuilder.AppendFormat("\tController:{0}\r\n", controllerName);
strBuilder.AppendFormat("\tAction:{0}\r\n", actionName);
strBuilder.AppendFormat("\tExceptionInfo:{0}\r\n", filterContext.Exception);
//ToTest
//MailHelper mail = new MailHelper("smtp.gmail.com", "[email protected]", "gzlpsmyx");
//mail.Send("System", "[email protected]", "资产系统出现错误!", strBuilder.ToString());
}
示例3: OnException
public override void OnException(ExceptionContext filterContext)
{
T_Log log = new T_Log();
//ToTest
log.UserId = 1;
log.UserName = "admin";
//log.UserId = Convert.ToInt32(filterContext.HttpContext.Session["UserId"]);
//log.UserName = filterContext.HttpContext.Session["UserName"].ToString();
log.IpAddress = NetHelper.GetPrivateIPAddress();
log.Controller = filterContext.GetController();
log.Action = filterContext.GetAction();
log.Remark = filterContext.Exception.Message;
log.CreateDate = DateTime.Now;
//ToTest
//using (DBEntity db = new DBEntity())
//{
// db.Log.AddObject(log);
// db.SaveChanges();
//}
}