当前位置: 首页>>代码示例>>C#>>正文


C# ExceptionContext.GetController方法代码示例

本文整理汇总了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;
    }
开发者ID:RockyMyx,项目名称:ASP.NetMvc-Bootstrap,代码行数:25,代码来源:LocalLogErrorAttribute.cs

示例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());
    }
开发者ID:RockyMyx,项目名称:ASP.NetMvc-Bootstrap,代码行数:15,代码来源:MailErrorAttribute.cs

示例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();
        //}
    }
开发者ID:RockyMyx,项目名称:ASP.NetMvc-Bootstrap,代码行数:23,代码来源:DBLogErrorAttribute.cs


注:本文中的System.Web.Mvc.ExceptionContext.GetController方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。