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

C# Mvc.HandleErrorInfo类代码示例

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

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



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

示例1: OnException

        public override void OnException(ExceptionContext filterContext)
        {

            if (filterContext == null) throw new ArgumentNullException("filterContext");
            if (filterContext.ExceptionHandled || !filterContext.HttpContext.IsCustomErrorEnabled) return;
            var exception = filterContext.Exception;
            if (new HttpException(null, exception).GetHttpCode() != 500) return;
            var controllerName = (string)filterContext.RouteData.Values["controller"];
            var actionName = (string)filterContext.RouteData.Values["action"];
            var model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);
            ActionResult result;
            if (IsJson)
                result = new JsonResult { Data = new { error = filterContext.Exception.Message }, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
            else {
                var dict = new ViewDataDictionary<HandleErrorInfo>(model);
                if (filterContext.Controller.ViewData.ContainsKey("KatushaUser")) dict.Add("KatushaUser", filterContext.Controller.ViewData["KatushaUser"]);
                if (filterContext.Controller.ViewData.ContainsKey("KatushaProfile")) dict.Add("KatushaProfile", filterContext.Controller.ViewData["KatushaProfile"]);
                dict.Add("HasLayout", HasLayout);
                result = new ViewResult { ViewName = ExceptionView, ViewData = dict, TempData = filterContext.Controller.TempData };
            }
            filterContext.Result = result;
            filterContext.ExceptionHandled = true;
            filterContext.HttpContext.Response.Clear();
            filterContext.HttpContext.Response.StatusCode = 500;
            filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
        }
开发者ID:ramazanaktolu,项目名称:MS.Katusha,代码行数:26,代码来源:KatushaFilterAttribute.cs


示例2: BadRequest

 public ActionResult BadRequest(string error)
 {
     var controllerName = (string)RouteData.Values["controller"];
     var actionName = (string)RouteData.Values["action"];
     var model = new HandleErrorInfo(new HttpException(500, error), controllerName, actionName);
     return View(model);
 }
开发者ID:cheshire-howe,项目名称:bluejeans,代码行数:7,代码来源:ErrorController.cs


示例3: OnException

        public void OnException(ExceptionContext filterContext)
        {
            // Log should go here
            if (filterContext.HttpContext.IsCustomErrorEnabled && !filterContext.ExceptionHandled)
            {
                string controllerName = (string)filterContext.RouteData.Values["controller"];
                string actionName = (string)filterContext.RouteData.Values["action"];
                HandleErrorInfo info = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);

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

                if (!filterContext.HttpContext.Request.IsAjaxRequest())
                {
                    var errorModel = new ErrorModel(filterContext.Exception.Message, filterContext.Exception, controllerName, actionName);
                    filterContext.Result = new ViewResult { ViewName = "Error" , ViewData = new ViewDataDictionary(errorModel), TempData = filterContext.Controller.TempData };
                }
                else
                {
                    // It should return an JSON response and application should be prepared to display it
                }

            }
        }
开发者ID:vvilella,项目名称:Telos.Admin,代码行数:26,代码来源:GlobalExceptionFilter.cs


示例4: OnException

        //Handles Exceptions in the Code
        public override void OnException(ExceptionContext filterContext)
        {
            filterContext.ExceptionHandled = true;
            var model = new HandleErrorInfo(filterContext.Exception, "Controller", "Action");

            //var directory = Path.GetFullPath("Log/ExceptionLog.txt");
            //StreamWriter LogWriter = new StreamWriter(directory, true);
            //LogWriter.WriteLine("{0}, {1}, {2}, {3}, {4}", DateTime.Now, filterContext.Exception.Message, filterContext.Exception.InnerException, filterContext.RouteData.Values["controller"], filterContext.RouteData.Values["action"]);
            //LogWriter.WriteLine("-----------------------------------------------------------------------------");
            //LogWriter.Close();

            if (filterContext.HttpContext.IsCustomErrorEnabled)
            {
                if (filterContext.HttpContext.Request.IsAjaxRequest())
                {
                    //if the request is an ajax request return the _Error view
                    filterContext.Result = new ViewResult()
                    {
                        ViewName = "_Error",
                        ViewData = new ViewDataDictionary(model)
                    };
                }
                else
                {
                    //if the request is not an ajax request return the Error view
                    filterContext.Result = new ViewResult()
                    {
                        ViewName = "Error",
                        ViewData = new ViewDataDictionary(model)
                    };
                }
            }
        }
开发者ID:gallfan,项目名称:FinalYearProject,代码行数:34,代码来源:Error.cs


示例5: HandleUnauthorizedRequest

        protected sealed override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            string resultMessage = HandleUnauthorizedMessage();
            string resultResource = BuildAuthorizeResource(filterContext);

            // Log Access Denied
            if (Token != null) // Don't log anonymous
                AuthorizationLog.LogAccessDenied(Token.User.UserId, resultResource, resultMessage);

            // Build Response View
            var ex = new AccessDeniedException(resultMessage, resultResource);
            HandleErrorInfo model = new HandleErrorInfo(ex, filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, filterContext.ActionDescriptor.ActionName);
            ViewResult result = new ViewResult
            {
                ViewName = "Error",
                MasterName = Token == null ? "_PublicLayout" : "_Layout",
                ViewData = new ViewDataDictionary<HandleErrorInfo>(model),
                TempData = filterContext.Controller.TempData
            };

            filterContext.Result = result;
            var contextResponse = filterContext.HttpContext.Response;
            contextResponse.Clear();
            contextResponse.StatusCode = (int)HttpStatusCode.Unauthorized;
            contextResponse.TrySkipIisCustomErrors = true;
        }
开发者ID:garysharp,项目名称:Disco,代码行数:26,代码来源:DiscoAuthorizeBaseAttribute.cs


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


示例7: HandleException

        public static void HandleException(this ExceptionContext filterContext)
        {
            var ex = filterContext.Exception;
            var contextResponse = filterContext.HttpContext.Response;

            LogException(ex);

            HttpException httpException = new HttpException(null, ex);
            int httpExceptionCode = httpException.GetHttpCode();

            string controllerName = (string)filterContext.RouteData.Values["controller"];
            string actionName = (string)filterContext.RouteData.Values["action"];
            HandleErrorInfo model = new HandleErrorInfo(ex, controllerName ?? "Unknown", actionName ?? "Unknown");
            ViewResult result = new ViewResult
            {
                ViewName = "Error",
                MasterName = "_Layout",
                ViewData = new ViewDataDictionary<HandleErrorInfo>(model),
                TempData = filterContext.Controller.TempData
            };
            
            filterContext.Result = result;
            filterContext.ExceptionHandled = true;
            contextResponse.Clear();
            contextResponse.StatusCode = httpExceptionCode;
            contextResponse.TrySkipIisCustomErrors = true;
        }
开发者ID:garysharp,项目名称:Disco,代码行数:27,代码来源:HelperExtensions.cs


示例8: AddActivity

        public ActionResult AddActivity(CRM_KA_ActivityModel ActivityModel, string CustomerID)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    ActivityModel.Id = System.Guid.NewGuid();
                    ActivityModel.CustomerID = CustomerID;

                    _KeyAccountManager.saveActivity(ActivityModel);
                    updateKeyAccount(CustomerID);

                    ViewData["CustomerID"] = CustomerID;

                    return PartialView("_KA_ActivityList");
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception ex)
            {
                var modal = new HandleErrorInfo(ex, "KeyAccount", "Index");
                return View("Error", modal);
            }
        }
开发者ID:ppsett,项目名称:PNK-Restful-service,代码行数:27,代码来源:KeyAccountController.cs


示例9: Index

 // GET: Error
 public ActionResult Index()
 {
     //If a 404 is thrown, the system redirects here but without a HandleErrorInfo object, so we make our own.
     HttpException err = new HttpException(404, string.Format("404 - Unrecognized Url - ({0})", Request.Params["aspxerrorpath"]));
     HandleErrorInfo model = new HandleErrorInfo(err, "Error", "Index");
     return View("Error", model);
 }
开发者ID:cbacon91,项目名称:VideoQuiz,代码行数:8,代码来源:ErrorController.cs


示例10: Login

        public ActionResult Login(string userId, string password)
        {
            AccountInfo info = new AccountInfo();

            if (ModelState.IsValid)
            {
                info.userid = userId;
                info.password = password;
                try {
                    using (svcClient = new AccountServiceClient())
                    {
                        if (svcClient.Authenticate(info))
                        {
                            Session["IsAuthenticated"] = true;
                            Session["User"] = userId;
                            return View("LoggedIn");
                        }
                    }
                }
                catch (FaultException<AccountServiceFault> ex)
                {
                    HandleErrorInfo errorInfo = new HandleErrorInfo(ex, "Home", "Login");
                    return View("Error", errorInfo);
                }

            }
            ViewBag.LoginFailed = "Oops... user credential is not matched, please try again!";
            return View();
        }
开发者ID:hma14,项目名称:AccountRegistrationApp,代码行数:29,代码来源:HomeController.cs


示例11: OnException

        public override void OnException(ExceptionContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }

            // If custom errors are disabled, we need to let the normal ASP.NET exception handler
            // execute so that the user can see useful debugging information.
            if (filterContext.ExceptionHandled || !filterContext.HttpContext.IsCustomErrorEnabled)
            {
                return;
            }

            Exception exception = filterContext.Exception;

            // If this is not an HTTP 500 (for example, if somebody throws an HTTP 404 from an action method),
            // ignore it.
            if (new HttpException(null, exception).GetHttpCode() != 500)
            {
                return;
            }

            if (!ExceptionType.IsInstanceOfType(exception))
            {
                return;
            }

            string controllerName = (string)filterContext.RouteData.Values["controller"];
            string actionName = (string)filterContext.RouteData.Values["action"];
            HandleErrorInfo model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);

            if (this._logger.IsErrorEnabled)
            {
                this._logger.Error(string.Format("An unexpected error occured while executing {0} in {1}.", actionName, controllerName), exception);
            }

            MessageViewData messageViewData = new MessageViewData();

            while (exception != null)
            {
                messageViewData.AddErrorMessage(this._localizer.GetString(exception.Message));
                exception = exception.InnerException;
            }
            var viewData = new ViewDataDictionary<HandleErrorInfo>(model);
            viewData["Messages"] = messageViewData;

            // Render error view
            filterContext.Result = new ViewResult
                                   	{
                                   		ViewName = View,
                                   		MasterName = Master,
                                   		ViewData = viewData,
                                   		TempData = filterContext.Controller.TempData
                                   	};

            filterContext.ExceptionHandled = true;
            filterContext.HttpContext.Response.Clear();
            filterContext.HttpContext.Response.StatusCode = 500;
        }
开发者ID:xwyangjshb,项目名称:cuyahoga,代码行数:60,代码来源:ExceptionFilter.cs


示例12: CreateTechnicalSupport

        public ActionResult CreateTechnicalSupport(TechnicalSupportModel entity)
        {
            if (_TechnicalSupportManager.getByID(entity.VisitedDate,entity.CustomerID,User.Identity.Name)!=null)
            {
                ModelState.AddModelError("*", "This Customer and Visited date are duplicated in record.");
                return View(new TechnicalSupportModel { CustomerID = entity.CustomerID }).WithErrorMessage("Duplicated record!");
            }
            try
            {
                // TODO: Add insert logic here
                entity.AttachGroupID = Guid.NewGuid();
                entity.CreatedBy = User.Identity.Name;
                entity.CreatedDate = DateTime.Today;

                _TechnicalSupportManager.Save(entity);

                List<FileAttachmentModel> FAList = (List<FileAttachmentModel>)Session["Attachment"];

                if (FAList != null)
                {
                    foreach (FileAttachmentModel item in FAList)
                    {
                        _FileAttachmentManager.Save(item,entity.AttachGroupID,User.Identity.Name);
                    }
                }
                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                var modal = new HandleErrorInfo(ex, "TechnicalSupport", "CreateTechnicalSupport");
                return View("Error", modal);
            }
        }
开发者ID:ppsett,项目名称:PNK-Restful-service,代码行数:33,代码来源:TechnicalSupportController.cs


示例13: OnException

        /// <summary>
        /// 异常处理
        /// </summary>
        /// <param name="filterContext">当前请求</param>
        protected override void OnException(ExceptionContext filterContext)
        {
            Exception exception = filterContext.Exception;
            string message;
            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                if (exception is HttpAntiForgeryException)
                {
                   
                }
                //filterContext.Result = Json(new AjaxResult(message, AjaxResultType.Error));
                //filterContext.ExceptionHandled = true;
            }
            else
            {

                var error = new HandleErrorInfo(
                    exception,
                    filterContext.RouteData.Values["controller"].ToString(),
                    filterContext.RouteData.Values["action"].ToString());

                filterContext.Result = View("Error", error);
                filterContext.ExceptionHandled = true;
            }
        }
开发者ID:leloulight,项目名称:Magicodes.NET,代码行数:29,代码来源:AdminControllerBase.cs


示例14: OnException

 public virtual void OnException(ExceptionContext filterContext)
 {
     if (filterContext == null)
     {
         throw new ArgumentNullException("filterContext");
     }
     if (!filterContext.IsChildAction && (!filterContext.ExceptionHandled && filterContext.HttpContext.IsCustomErrorEnabled))
     {
         Exception innerException = filterContext.Exception;
         if ((new HttpException(null, innerException).GetHttpCode() == 404))
         {
             string controllerName = (string)filterContext.RouteData.Values["controller"];
             string actionName = (string)filterContext.RouteData.Values["action"];
             HandleErrorInfo model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);
             ViewResult result = new ViewResult
             {
                 ViewName = this.View,
                 MasterName = this.Master,
                 ViewData = new ViewDataDictionary<HandleErrorInfo>(model),
                 TempData = filterContext.Controller.TempData
             };
             filterContext.Result = result;
             filterContext.ExceptionHandled = true;
             filterContext.HttpContext.Response.Clear();
             filterContext.HttpContext.Response.StatusCode = 404;
             filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
             filterContext.HttpContext.Response.ClearHeaders();
         }
     }
 }
开发者ID:Mangon2015,项目名称:Mangon.FrameWork.MVC,代码行数:30,代码来源:ALLExceptErrorAttribute.cs


示例15: addAuthenticatedUser

        public ContentResult addAuthenticatedUser(string UserID)
        {
            try
            {
                if (ModelState.IsValid)
                {
                     HttpCookie CK = HttpContext.Request.Cookies.Get("LoginDetail");

                     if (CK != null)
                     {
                         SecurityUserModel entity = new SecurityUserModel();
                         entity.UserID = UserID;
                         entity.SubsystemID = Int32.Parse(CK.Values["SubSystemID"].ToString());

                         _SecurityManager.Save(entity);

                         return Content("success");
                     }
                     else
                     {
                         return Content("fail");
                     }
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception ex)
            {
                var modal = new HandleErrorInfo(ex, "SecuritySetting", "index");
                return Content("fail");
            }
        }
开发者ID:ppsett,项目名称:PNK-Restful-service,代码行数:34,代码来源:SecuritySettingController.cs


示例16: OnException

        public void OnException(ExceptionContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }
            if (filterContext.ExceptionHandled || !filterContext.HttpContext.IsCustomErrorEnabled)
            {
                return;
            }

            Exception exception = filterContext.Exception;
            if (new HttpException(null, exception).GetHttpCode() != 404)
            {
                return;
            }

            string controllerName = (string)filterContext.RouteData.Values["controller"];
            string actionName = (string)filterContext.RouteData.Values["action"];
            HandleErrorInfo model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);
            filterContext.Result = new ViewResult
            {
                ViewName = this.View,
                MasterName = this.Master,
                ViewData = new ViewDataDictionary<HandleErrorInfo>(model),
                TempData = filterContext.Controller.TempData
            };
            filterContext.ExceptionHandled = true;
            filterContext.HttpContext.Response.Clear();
            filterContext.HttpContext.Response.StatusCode = 500;
            filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
        }
开发者ID:mkhj,项目名称:EcoHotels,代码行数:32,代码来源:HandleNotFoundAttribute.cs


示例17: CreateActionResult

        protected virtual ActionResult CreateActionResult(ExceptionContext filterContext, int statusCode)
        {
            var ctx = new ControllerContext(filterContext.RequestContext, filterContext.Controller);
            var statusCodeName = ((HttpStatusCode)statusCode).ToString();
            var exceptionName = filterContext.Exception.GetType().Name.Replace("Exception", "");

            var viewName = string.Empty;
            viewName = SelectFirstView(ctx,
                                                "~/Views/Error/{0}.cshtml".FormatWith(exceptionName),
                                                "~/Views/Error/{0}.cshtml".FormatWith(statusCode),
                                                "~/Views/Error/{0}.cshtml".FormatWith(statusCodeName),
                                                "~/Views/Error/UnexpectedError.cshtml");

            var controllerName = "Error";
            var actionName = "Index";
            var model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);
            var result = new ViewResult
                                {
                                    ViewName = viewName,
                                    ViewData = new ViewDataDictionary<HandleErrorInfo>(model)
                                };
            result.ViewBag.StatusCode = statusCode;

            filterContext.RouteData.Values["view"] = viewName.Replace("~/Views/Error/", "").Replace(".cshtml", "");

            return result;
        }
开发者ID:winmissupport,项目名称:FeatureUpate,代码行数:27,代码来源:HandleExigoErrorAttribute.cs


示例18: OnException

        public override void OnException(ExceptionContext filterContext)
        {
            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                filterContext.Result = new JsonResult
                {
                    Data = new
                    {
                        result = 0,
                        message = filterContext.Exception.Message
                    },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };
            }
            else
            {
                var controllerName = (string)filterContext.RouteData.Values["controller"];
                var actionName = (string)filterContext.RouteData.Values["action"];
                var model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);

                filterContext.Result = new ViewResult
                {
                    ViewName = View,
                    MasterName = Master,
                    ViewData = new ViewDataDictionary<HandleErrorInfo>(model),
                    TempData = filterContext.Controller.TempData
                };
            }

            filterContext.ExceptionHandled = true;
            filterContext.HttpContext.Response.Clear();
            filterContext.HttpContext.Response.StatusCode = 500;
            filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
        }
开发者ID:shadowzcw,项目名称:nCommon,代码行数:34,代码来源:CustomHandleErrorAttribute.cs


示例19: OnException

        public virtual void OnException(ExceptionContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }

            if (filterContext.IsChildAction)
            {
                return;
            }

            // If custom errors are disabled, we need to let the normal ASP.NET exception handler
            // execute so that the user can see useful debugging information.
            if (filterContext.ExceptionHandled || !filterContext.HttpContext.IsCustomErrorEnabled)
            {
                return;
            }

            string controllerName = (string)filterContext.RouteData.Values["controller"];
            string actionName = (string)filterContext.RouteData.Values["action"];
            HandleErrorInfo model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);

            filterContext.Result = new ErrorResult
            {
                StatusCode = HttpStatusCode.InternalServerError,
                ViewData = new ViewDataDictionary<HandleErrorInfo>(model)
            };

            filterContext.ExceptionHandled = true;
        }
开发者ID:nathanbedford,项目名称:ScaffR-Generated,代码行数:31,代码来源:CustomHandleErrorAttribute.cs


示例20: OnException

 protected override void OnException(ExceptionContext filterContext)
 {
     var error = new HandleErrorInfo(
         filterContext.Exception,
         filterContext.RouteData.Values["controller"].ToString(),
         filterContext.RouteData.Values["controller"].ToString());
     View("Error", error).ExecuteResult(ControllerContext);
 }
开发者ID:karl-liu,项目名称:lunchaccounting,代码行数:8,代码来源:ControllerBase.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Mvc.HtmlHelper类代码示例发布时间:2022-05-26
下一篇:
C# Mvc.FormCollection类代码示例发布时间: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