• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Mvc.ExceptionContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Web.Mvc.ExceptionContext的典型用法代码示例。如果您正苦于以下问题:C# ExceptionContext类的具体用法?C# ExceptionContext怎么用?C# ExceptionContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ExceptionContext类属于System.Web.Mvc命名空间,在下文中一共展示了ExceptionContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: OnException

        public override void OnException(ExceptionContext context)
        {
            base.OnException(context);

            if (!context.ExceptionHandled)
                LogException(context.Exception);
        }
开发者ID:modulexcite,项目名称:framework-1,代码行数:7,代码来源:HandleErrorUsingLogger.cs


示例2: getStatusCodeHelper

        //Helpers--------------------------------------------------------------------------------------------------------------//
        #region Helpers


        //getStatusCodeHelper
        private HttpStatusCode getStatusCodeHelper(ExceptionContext exceptionContext)
        {
            var exceptionType = exceptionContext.Exception.GetBaseException().GetType();
            if (exceptionType == typeof(ArgumentNullException)) { return HttpStatusCode.BadRequest; }
            if (exceptionType == typeof(DbBadRequestException)) { return HttpStatusCode.BadRequest; }
            return HttpStatusCode.InternalServerError;
        }
开发者ID:naishan,项目名称:SDDB,代码行数:12,代码来源:DBExceptionAttribute.cs


示例3: Abnormal

        /// <summary>
        /// 处理异常,将异常保存到数据库
        /// </summary>
        /// <param name="filterContext"></param>
        public void Abnormal(ExceptionContext filterContext)
        {
            MODEL.T_Abnormal abnormal = new MODEL.T_Abnormal();
            string stack = filterContext.Exception.StackTrace;
            string[] str = stack.Split('.');
            string area = str[0];
            string controller = str[1];
            string action = str[2];
            string[] str1 = action.Split('(');
            string reallyaction = str1[0];
            abnormal.Area = area;
            abnormal.Controller = controller;
            abnormal.ACtion = reallyaction;
            abnormal.Message = filterContext.Exception.Message;
            OperateContext.Current.BLLSession.IAbnormalBLL.Add(abnormal);
            //接下来在配置文件设置重定向
            //注意:customErrors要放在system.web下

            //string filePath = Server.MapPath("~/ExcelModel/Exception.txt");
            //FileInfo file = new FileInfo(filePath);
            //if (!file.Exists)
            //{
            //    file.Create().Close();
            //}
            //StreamWriter sw = System.IO.File.AppendText(filePath);
        }
开发者ID:RuiHuaLiang,项目名称:FinalabBMS-1,代码行数:30,代码来源:GetAbnormal.cs


示例4: OnException

 protected override void OnException(ExceptionContext filterContext)
 {
     filterContext.ExceptionHandled = true;
     string exceptionPolicy = this.ExceptionPolicyName;
     if (string.IsNullOrEmpty(exceptionPolicy))
     {
         exceptionPolicy = DefautExceptionPolicyName;
     }
     try
     {
         if (ExceptionPolicy.HandleException(filterContext.Exception, exceptionPolicy))
         {
             base.OnException(filterContext);
         }
         else
         {
             this.ModelState.AddModelError(Guid.NewGuid().ToString(), filterContext.Exception);
             filterContext.Result = this.View();
         }
     }
     catch (Exception ex)
     {
         filterContext.Exception = ex;
         base.OnException(filterContext);
     }
 }
开发者ID:huoxudong125,项目名称:WCF-Demo,代码行数:26,代码来源:ExtendedController.cs


示例5: 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


示例6: OnException

        public void OnException(ExceptionContext filterContext)
        {
            if (filterContext.Controller is ServiceController)
            {
                ServiceController controller = (ServiceController)filterContext.Controller;

                object model;
                int httpStatusCode = (int)HttpStatusCode.InternalServerError;

                IServiceException serviceException = filterContext.Exception as IServiceException;
                if (serviceException!=null)
                {
                    model = serviceException.Model;
                    httpStatusCode = (int)serviceException.StatusCode;
                }
                else
                {
                    model = ExceptionToErrorModel(filterContext.Exception);
                }

                // Sort the accept types acceptable to the client into order of preference then look for
                // a response handler that supports one of the accept types.
                foreach (var contentTypeWrapper in ActionInvoker.GetAcceptHeaderContentTypes(controller.RequestInfo.AcceptTypes))
                {
                    var replacementResult = NServiceMVC.Formatter.CreateContentResult(contentTypeWrapper.ContentType.ToString(), model);

                    if (replacementResult != null)
                    {
                        filterContext.Result = new HttpStatusContentResult(httpStatusCode, replacementResult);
                        filterContext.ExceptionHandled = true;
                        return;
                    }
                }
            }
        }
开发者ID:sdupre,项目名称:NServiceMVC,代码行数:35,代码来源:NsExceptionFilter.cs


示例7: OnException

        public override void OnException(ExceptionContext filterContext)
        {
            if (filterContext.ExceptionHandled)
            {
                return;
            }
            if (ExceptionType.IsInstanceOfType(filterContext.Exception) == false)
            {
                return;
            }

            ActionResult result;
            if (filterContext.Exception.GetType() == typeof(ApplicationException))
            {

                Console.ReadLine();
                //result = GetCustomException(filterContext);
                //filterContext.HttpContext.Response.StatusCode = 400;
                //var id = GenerateNewGuid();
                //LogException(filterContext.Exception, id);
            }

            else
            {
            }
        }
开发者ID:Cbrown208,项目名称:cbrownRepository,代码行数:26,代码来源:Program.cs


示例8: OnException

        /// <summary>
        /// Called when an exception occurs.
        /// </summary>
        /// <param name="filterContext">The filter context.</param>
        public override void OnException(ExceptionContext filterContext)
        {
            if (filterContext != null && filterContext.Exception != null)
            {
                //Call exception handler for logging the exception
                ExceptionManager.HandleException(filterContext.Exception);

                // Handling HTTP & Ajax requests.
                filterContext.ExceptionHandled = true;

                if (!filterContext.HttpContext.Request.IsAjaxRequest())
                {
                    // storing errormessage and stacktrace
                    SessionStateManager<ErrorState>.Data.ErrorMessage = filterContext.Exception.Message;
                    SessionStateManager<ErrorState>.Data.StackTrace = filterContext.Exception.StackTrace;

                    // preparing redirect url
                    Controller controller = (Controller)filterContext.Controller;
                    string redirectUrl = controller.Url.SmartAction(ErrorControllerAction, ErrorController);

                    filterContext.Result = new RedirectResult(redirectUrl);
                }
                else
                {
                    filterContext.Result = OperationResult<bool>.CreateErrorResult(
                                           filterContext.Exception.Message,
                                           filterContext.Exception.StackTrace).ToJsonResult();
                }
            }
        }
开发者ID:tmccord123,项目名称:TMCDev,代码行数:34,代码来源:JCCExceptionHandlerAttribute.cs


示例9: OnException

        public void OnException(ExceptionContext filterContext)
        {
            if (filterContext.ExceptionHandled == true)
            {
                HttpException httpExp = filterContext.Exception as HttpException;
                if (httpExp.GetHttpCode() != 500)
                    return;
            }

            HttpException httpException = filterContext.Exception as HttpException;
            if (httpException != null)
            {
                filterContext.Controller.ViewBag.UrlRefer = filterContext.HttpContext.Request.UrlReferrer;
                filterContext.HttpContext.Session["CurrentException"] = httpException;
                if (httpException.GetHttpCode() == 404)
                {
                    filterContext.HttpContext.Response.Redirect("~/Login/NotFound");

                }
                else if (httpException.GetHttpCode() == 500)
                {
                    filterContext.HttpContext.Response.Redirect("~/Login/InternalError");
                    //filterContext.Result = new ViewResult() { ViewName = "InternalError", ViewData = filterContext.Controller.ViewData };
                    //filterContext.Result=new RedirectToRouteResult(("Default", new RouteValueDictionary(new { controller = "Login", action = "InternalError",route}));
                }
                //else if (httpException.GetHttpCode() == 900)
                //{
                //    filterContext.HttpContext.Response.Redirect("~/Login/SignIn");
                //}
            }

            //record log in file

            filterContext.ExceptionHandled = true;//indicate the exp is handled
        }
开发者ID:ellefry,项目名称:RBCD.ToolManagement,代码行数:35,代码来源:CustomExceptionAttribute.cs


示例10: OnException

        public void OnException(ExceptionContext filterContext)
        {
            Exception exception = filterContext.Exception;
            string message;
            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                message = "Ajax访问时引发异常:";
                AjaxResult ajaxResult = null;
                if (exception is BusinessException)
                {
                    message = exception.Message;
                    ajaxResult = new AjaxResult(message, AjaxResultType.Warning);
                }
                else if (exception is HttpAntiForgeryException)
                {
                    message += "安全性验证失败。<br>请刷新页面重试,详情请查看系统日志。";
                }
                else
                {
                    message += exception.Message;
                }

                filterContext.Result = new JsonResult() { Data = ajaxResult ?? new AjaxResult(message, AjaxResultType.Error) };
                filterContext.ExceptionHandled = true;
            }
            else
            {
                filterContext.Result = new ContentResult() { Content = "系统异常:" + exception.Message };
            }
        }
开发者ID:Deson621,项目名称:demo,代码行数:30,代码来源:ExceptionFilter.cs


示例11: OnException

 protected override void OnException(ExceptionContext filterContext)
 {
     try
     {
         StoreFrontConfiguration storeFrontConfig = GStoreDb.GetCurrentStoreFrontConfig(Request, true, false);
         if (storeFrontConfig == null)
         {
             AddUserMessage("Store Front Inactive or not found!", "Sorry, this URL does not point to an active store front. Please contact us for assistance.", AppHtmlHelpers.UserMessageType.Danger);
             filterContext.ExceptionHandled = true;
             RedirectToAction("Index", "Home", new { area = "" }).ExecuteResult(this.ControllerContext);
         }
     }
     catch (Exceptions.StoreFrontInactiveException)
     {
         AddUserMessage("Store Front Inactive!", "Sorry, this URL points to an Inactive Store Front. Please contact us for assistance.", AppHtmlHelpers.UserMessageType.Danger);
         filterContext.ExceptionHandled = true;
         RedirectToAction("Index", "Home", new { area = "" }).ExecuteResult(this.ControllerContext);
     }
     catch (Exceptions.NoMatchingBindingException)
     {
         AddUserMessage("Store Front Not Found!", "Sorry, this URL does not point to an active store front. Please contact us for assistance.", AppHtmlHelpers.UserMessageType.Danger);
         filterContext.ExceptionHandled = true;
         RedirectToAction("Index", "Home", new { area = "" }).ExecuteResult(this.ControllerContext);
     }
     catch (Exception)
     {
         throw;
     }
     base.OnException(filterContext);
 }
开发者ID:berlstone,项目名称:GStore,代码行数:30,代码来源:BlogAdminBaseController.cs


示例12: LogExceptionDetails

        private void LogExceptionDetails(ExceptionContext exceptionContext)
        {
            var builder = new StringBuilder();
            builder.Append("Unhandled exception from ");

            builder.AppendFormat(" {0}", exceptionContext.HttpContext.Request.UserHostAddress);
            string forwardedFor = exceptionContext.HttpContext.Request.Headers.Get("X-Forwarded-For");
            if (!string.IsNullOrWhiteSpace(forwardedFor))
            {
                builder.AppendFormat(" ({0})", forwardedFor);
            }

            builder.AppendFormat(" to: {0}", exceptionContext.HttpContext.Request.RawUrl);
            builder.AppendFormat(
                    " - {0}/{1} {2}",
                    exceptionContext.Controller.ControllerContext.RouteData.Values["controller"],
                    exceptionContext.Controller.ControllerContext.RouteData.Values["action"],
                    exceptionContext.HttpContext.Request.HttpMethod);

            builder.Append(Environment.NewLine);
            builder.Append("-------------");
            builder.Append(Environment.NewLine);
            builder.Append(exceptionContext.Exception);

            _log.Error(builder.ToString(), exceptionContext.Exception);
        }
开发者ID:huutoannht,项目名称:mart,代码行数:26,代码来源:HandleErrorAttribute.cs


示例13: OnException

 protected override void OnException(ExceptionContext filterContext)
 {
     if (filterContext == null) return;
     //记录异常信息
     ApplicationContext.ApplicationLog.Log(LoggerLevels.Error, filterContext.Exception);
     base.OnException(filterContext);
 }
开发者ID:leloulight,项目名称:Magicodes.NET,代码行数:7,代码来源:PlusControllerBase.cs


示例14: OnException

		public void OnException(ExceptionContext filterContext)
		{
			if (!(filterContext.Exception is HttpAntiForgeryException))
				return;
			filterContext.Result = new RedirectResult("/");
			filterContext.ExceptionHandled = true;
		}
开发者ID:kontur-edu,项目名称:uLearn,代码行数:7,代码来源:FilterConfig.cs


示例15: OnException

        protected override void OnException(ExceptionContext filterContext)
        {
            //Exception exception = filterContext.Exception;
            //string message;
            //if (filterContext.HttpContext.Request.IsAjaxRequest())
            //{
            //    message = "Ajax访问时引发异常:";
            //    AjaxResult ajaxResult = null;
            //    if (exception is BusinessException)
            //    {
            //        message = exception.Message;
            //        ajaxResult = new AjaxResult(message, AjaxResultType.Warning);
            //    }
            //    else if (exception is HttpAntiForgeryException)
            //    {
            //        message += "安全性验证失败。<br>请刷新页面重试,详情请查看系统日志。";
            //    }
            //    else
            //    {
            //        message += exception.Message;
            //    }

            //    filterContext.Result = Json(ajaxResult??new AjaxResult(message, AjaxResultType.Error));
            //    filterContext.ExceptionHandled = true;
            //}
            //else
            //{
            //    filterContext.Result =Content("系统异常:"+exception.Message);
            //}
        }
开发者ID:Deson621,项目名称:demo,代码行数:30,代码来源:BaseController.cs


示例16: OnException

 public void OnException( ExceptionContext filterContext )
 {
     _logger.Error(filterContext.Exception, filterContext.RouteData.Values["controller"] + "." + filterContext.RouteData.Values["action"]
         + filterContext.Exception.StackTrace.Split( '\n' ) [0] );
     filterContext.ExceptionHandled = true;
     filterContext.Result = new ContentResult { Content = "Disaster occured" };
 }
开发者ID:MaxShustov,项目名称:GameStore,代码行数:7,代码来源:ExceptionFilterAttribute.cs


示例17: OnException

        protected override void OnException(ExceptionContext filterContext)
        {
            String Errormsg = String.Empty;
            Exception unhandledException = new Exception("BASE ERROR");
            if (Server.GetLastError() != null)
                unhandledException = Server.GetLastError();
            else
                unhandledException = filterContext.Exception;
            Exception httpException = unhandledException as Exception;
            Errormsg = "發生例外網頁:{0}錯誤訊息:{1}";
            if (httpException != null /*&& !httpException.GetType().IsAssignableFrom(typeof(HttpException))*/)
            {
                Errormsg = String.Format(Errormsg, Request.Path + Environment.NewLine,unhandledException.GetBaseException().ToString() + Environment.NewLine);

                Url = System.Web.HttpContext.Current.Request.Url.PathAndQuery;
                controller = Convert.ToString(ControllerContext.RouteData.Values["controller"]);
                action = Convert.ToString(ControllerContext.RouteData.Values["action"]);
                area = Convert.ToString(ControllerContext.RouteData.DataTokens["area"]);
                NLog.Logger logger = LogManager.GetCurrentClassLogger();
                logger.Error(Url + "|controller|" + controller + "|action|" + action + "|area|" + area + "|" + Errormsg);

            }
            base.OnException(filterContext);
            filterContext.ExceptionHandled = true;
        }
开发者ID:yang7129,项目名称:ASPNETSolution,代码行数:25,代码来源:baseController.cs


示例18: OnException

        public void OnException(ExceptionContext filterContext)
        {
            if (filterContext.Exception != null)
            {
                string friendlyCaption = "An error has occured.";
                string friendlyMessage = filterContext.Exception.Message;
                string technicalDetails = filterContext.Exception.ToString();

                filterContext.Result = new JsonResult
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new
                    {
                        caption = friendlyCaption,
                        message = friendlyMessage,
                        details = technicalDetails
                    }
                };

                filterContext.ExceptionHandled = true;
                filterContext.HttpContext.Response.Clear();
                filterContext.HttpContext.Response.StatusCode = 500;

                // Certain versions of IIS will sometimes use their own error page when
                // they detect a server error. Setting this property indicates that we
                // want it to try to render ASP.NET MVC's error page instead.
                filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
            }
        }
开发者ID:jpoehls,项目名称:WebFormsToMvcDemo,代码行数:29,代码来源:HandleAjaxErrorAttribute.cs


示例19: OnException

 /// <summary>
 /// 
 /// </summary>
 /// <param name="filterContext"></param>
 public override void OnException(ExceptionContext filterContext)
 {
     if (filterContext != null && filterContext.Exception != null)
     {
         logger.Error(filterContext.Exception);
     }
 }
开发者ID:majilik,项目名称:RecruitmentSystem,代码行数:11,代码来源:LogException.cs


示例20: OnException

 protected override void OnException(ExceptionContext filterContext)
 {
     // 标记异常已处理
     filterContext.ExceptionHandled = true;
     // 跳转到错误页
     filterContext.Result = new RedirectResult(Url.Action("Error", "Shared"));
 }
开发者ID:xiaolin8,项目名称:AMS,代码行数:7,代码来源:BaseController.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Mvc.FormCollection类代码示例发布时间:2022-05-26
下一篇:
C# Mvc.ControllerDescriptor类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap