示例#1
0
        protected override void OnException(ExceptionContext filterContext)
        {
            if (IsAjax(filterContext))
            {
                filterContext.ExceptionHandled = true;
                filterContext.HttpContext.Response.Clear();
                filterContext.HttpContext.Response.ContentEncoding        = Encoding.UTF8;
                filterContext.HttpContext.Response.HeaderEncoding         = Encoding.UTF8;
                filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
                filterContext.HttpContext.Response.StatusCode             = 400;
                var myobj = filterContext.Exception as System.ServiceModel.FaultException;
                if (myobj != null)
                {
                    MessageFault mf = myobj.CreateMessageFault();
                    if (mf.HasDetail)
                    {
                        ExcepcionLDS e = mf.GetDetail <ExcepcionLDS>();
                        if (e != null)
                        {
                            ViewBag.Path         = Request.Url.Host;
                            filterContext.Result = View("../Errores/ErrorJsons", e);
                        }
                    }
                }
                else
                {
                    Exception    e = filterContext.Exception;
                    ExcepcionLDS excLDS;
                    excLDS = new ExcepcionLDS()
                    {
                        categoria = Convert.ToInt32(LuzdelSur.Plataforma.Explorador.WCFEntity.TipoErrorControlado.Grave)
                        ,
                        mensajeUsuario = "Error en el procesamiento de la solicitud"
                        ,
                        mensajeAplicacion = e.Message
                    };

                    ViewBag.Path         = Request.Url.Host;
                    filterContext.Result = View("../Errores/ErrorJsons", excLDS);
                }
            }
            else
            {
                filterContext.ExceptionHandled = true;
                Exception       e = filterContext.Exception;
                string          controllerName = (string)filterContext.RouteData.Values["controller"];
                string          actionName     = (string)filterContext.RouteData.Values["action"];
                HandleErrorInfo model          = new HandleErrorInfo(e, controllerName, actionName);
                ViewBag.Path         = Request.Url.Host;
                filterContext.Result = PartialView("../Errores/ErrorVistas", model);
            }
        }
示例#2
0
        public override void OnException(ExceptionContext filterContext)
        {
            filterContext.ExceptionHandled = true;
            var model = new HandleErrorInfo(filterContext.Exception, "Controller", "Action");

            filterContext.Result = new ViewResult()
            {
                ViewName = "Error",
                ViewData = new ViewDataDictionary(model)
            };
            Errors.Write(filterContext.Exception);
            base.OnException(filterContext);
        }
        protected override void OnException(ExceptionContext filterContext)
        {
            Exception ex = filterContext.Exception;

            filterContext.ExceptionHandled = true;
            var model = new HandleErrorInfo(filterContext.Exception, "Controller", "Action");

            filterContext.Result = new ViewResult()
            {
                ViewName = "Error",
                ViewData = new ViewDataDictionary(model)
            };
        }
示例#4
0
        public override void OnException(ExceptionContext filterContext)
        {
            Exception e = filterContext.Exception;

            filterContext.ExceptionHandled = true;
            var model = new HandleErrorInfo(filterContext.Exception, "Exception", "Index");

            filterContext.Result = new ViewResult()
            {
                ViewName = "~/Views/Error/Exception.cshtml",
                ViewData = new ViewDataDictionary(model)
            };
        }
示例#5
0
        public override void OnException(ExceptionContext filterContext)
        {
            Exception ex = filterContext.Exception;

            filterContext.ExceptionHandled = true;
            var model = new HandleErrorInfo(filterContext.Exception, filterContext.RouteData.Values["controller"].ToString(), filterContext.RouteData.Values["action"].ToString());

            filterContext.Result = new ViewResult()
            {
                ViewName = "Error",
                ViewData = new ViewDataDictionary(model)
            };
        }
        // GET: Profile/Roles/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                HandleErrorInfo handeError = new HandleErrorInfo(new Exception(E.Message), "Roles", "Edit");
                return(View("Error", handeError));
            }
            MVRolesSetting RS = new MVRolesSetting();

            RS = RS.Update(id);

            return(View(RS));
        }
        public void OnException(ExceptionContext filterContext)
        {
            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 = "Error",
                ViewData = new ViewDataDictionary <HandleErrorInfo>(model)
            };
            filterContext.ExceptionHandled = true;
        }
示例#8
0
        public override void OnException(ExceptionContext filterContext)
        {
            Exception ex    = filterContext.Exception; filterContext.ExceptionHandled = true;
            var       model = new HandleErrorInfo(filterContext.Exception, "Controller", "Action");

            // Log Exception ex in database
            CreateLogFiles.ErrorLog("ControllerName Name" + model.ControllerName + "\t Action Name" + model.ActionName + "Error:" + model.Exception.Message + " \t  InnerException:" + model.Exception.InnerException + "Error StackTrace:" + model.Exception.StackTrace);
            // Notify  admin team
            filterContext.Result = new ViewResult()
            {
                ViewName = "Error", ViewData = new ViewDataDictionary(model)
            };
        }
示例#9
0
        protected override void OnException(ExceptionContext filterContext)
        {
            filterContext.ExceptionHandled = true;
            string controller = (string)RouteData.Values["controller"];
            string action     = (string)RouteData.Values["action"];
            var    model      = new HandleErrorInfo(filterContext.Exception, controller, action);

            filterContext.Result = new ViewResult
            {
                ViewName = "Error",
                ViewData = new ViewDataDictionary(model)
            };
        }
示例#10
0
 public ActionResult LinkLogin(string provider)
 {
     try
     {
         // Request a redirect to the external login provider to link a login for the current user
         return(new AccountController.ChallengeResult(provider, Url.Action("LinkLoginCallback", "Manage"), User.Identity.GetUserId()));
     }
     catch (Exception ex)
     {
         HandleErrorInfo error = new HandleErrorInfo(ex, "Manage", "LinkLogin");
         return(RedirectToAction("Index", "Error", new { model = error }));
     }
 }
 public ActionResult LogOff()
 {
     try
     {
         AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
         return(RedirectToAction("Index", "Home"));
     }
     catch (Exception ex)
     {
         HandleErrorInfo error = new HandleErrorInfo(ex, "Account", "LogOff");
         return(RedirectToAction("Index", "Error", new { model = error }));
     }
 }
 public ActionResult Login(string returnUrl)
 {
     try
     {
         ViewBag.ReturnUrl = returnUrl;
         return(View());
     }
     catch (Exception ex)
     {
         HandleErrorInfo error = new HandleErrorInfo(ex, "Account", "Login");
         return(RedirectToAction("Index", "Error", new { model = error }));
     }
 }
        public override void OnException(ExceptionContext filterContext)
        {
            var exceptionHandleInfo = new HandleErrorInfo(filterContext.Exception, "Controller", "Action");
            var context             = filterContext;

            filterContext.ExceptionHandled = true;

            filterContext.Result = new ViewResult()
            {
                ViewName = View,
                ViewData = new ViewDataDictionary(exceptionHandleInfo),
            };
        }
        // GET: Profile/Page/Edit/5
        public ActionResult Edit(int id)
        {
            Page page = db.Pages.Find(id);

            if (page == null)
            {
                E = new Error(1);
                HandleErrorInfo handeError = new HandleErrorInfo(new Exception(E.Message), "Roles", "Edit");
                return(View("Error", handeError));
            }
            ViewBag.ParentID = new SelectList(db.Pages.Where(p => p.ParentID == null && p.IsActive == true), "ID", "Name", page.ParentID);
            return(View(page));
        }
        public ActionResult Error(Exception exception)
        {
            CheckBetaFlag();

            HandleErrorInfo model = null;

            if (exception != null)
            {
                model = new HandleErrorInfo(exception, "unknown", "unknown");
            }

            return(View(model));
        }
示例#16
0
            public override void OnException(ExceptionContext filterContext)
            {
                Exception ex = filterContext.Exception;

                filterContext.ExceptionHandled = true;
                var model = new HandleErrorInfo(filterContext.Exception, "Cart", "UpdateCart");

                filterContext.Result = new ViewResult()
                {
                    ViewName = "Index",
                    ViewData = new ViewDataDictionary(model)
                };
            }
示例#17
0
        public ActionResult Handle(HandleErrorInfo info, bool isAjax)
        {
            if (info.Exception.GetType() == typeof(GenericADOException))
            {
                var sqLiteException = info.Exception.InnerException as SQLiteException;
                if (sqLiteException != null)
                {
                    return(Handle(sqLiteException));
                }
            }

            return(null);
        }
示例#18
0
        protected virtual ActionResult CreateActionResult(ExceptionContext filterContext, int statusCode)
        {
            var ctx            = new ControllerContext(filterContext.RequestContext, filterContext.Controller);
            var statusCodeName = ((HttpStatusCode)statusCode).ToString();

            string             viewName = null;
            ViewDataDictionary viewData = null;

            if (filterContext.Exception.GetType() == typeof(BusinessRuleException))
            {
                viewName = SelectFirstView(ctx,
                                           "~/Views/Error/UnAuthorized.cshtml",
                                           "~/Views/Error/General.cshtml",
                                           statusCodeName,
                                           "Error");

                string username = filterContext.HttpContext.User.Identity.Name;

                var          baseModel = ((BaseController)filterContext.Controller).GetBaseObject();
                UnAuthorized model     = new UnAuthorized(baseModel)
                {
                    Exception = filterContext.Exception
                };

                viewData = new ViewDataDictionary <UnAuthorized>(model);
            }
            else
            {
                viewName = SelectFirstView(ctx,
                                           string.Format("~/Views/Error/{0}.cshtml", statusCodeName),
                                           "~/Views/Error/General.cshtml",
                                           statusCodeName,
                                           "Error");

                var controllerName = (string)filterContext.RouteData.Values["controller"];
                var actionName     = (string)filterContext.RouteData.Values["action"];

                HandleErrorInfo model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);
                viewData = new ViewDataDictionary <HandleErrorInfo>(model);
            }


            var result = new ViewResult
            {
                ViewName = viewName,
                ViewData = viewData,
            };

            result.ViewBag.StatusCode = statusCode;
            return(result);
        }
        public override 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;
            }

            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() == 404)
            {
                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   = "404",
                    MasterName = Master,
                    ViewData   = new ViewDataDictionary <HandleErrorInfo>(model),
                    TempData   = filterContext.Controller.TempData
                };
                filterContext.ExceptionHandled = true;
                filterContext.HttpContext.Response.Clear();
                filterContext.HttpContext.Response.StatusCode = 404;

                // 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;
            }

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

            base.OnException(filterContext);
        }
示例#20
0
        public override void OnException(ExceptionContext filterContext)
        {
            //When exception happens what should our application do?
            //• You need to catch the exception
            //	○ Get the exception details such as exception type
            //	○ Exception message
            //	○ Any inner exception
            //	○ StackTrace
            //	○ Date Time when exception happened
            //	○ For which user exception happened
            //	○ Browser which user is using when exception happened
            //• Log those exception, usually we log them in text files, sometimes DB but its rare
            //	○ We can use any popular 3rd party logging frameworks to log the exception
            //		§ Nlog
            //		§ SeriLog
            //		§ Log4Net
            //	○ Download those from nuget
            //• Send emails when exception happens to the Development Team
            //• Always show a friendly error page to the user

            var controllerName = (string)filterContext.RouteData.Values["controller"];
            var actionName     = (string)filterContext.RouteData.Values["action"];

            base.OnException(filterContext);

            //create a Model for HandleErrorInfo, which is already built-in mvc
            var model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);

            var dateTimeExceptionHappened = DateTime.Now.TimeOfDay.ToString();
            var stackTrace       = filterContext.Exception.StackTrace;
            var exceptionMessage = filterContext.Exception.Message;
            var innerException   = filterContext.Exception.InnerException;

            //show info of the error view
            filterContext.Result = new ViewResult
            {
                ViewName   = View,
                MasterName = Master,
                ViewData   = new ViewDataDictionary <HandleErrorInfo>(model),
                TempData   = filterContext.Controller.TempData
            };
            //exception has been handled,
            filterContext.ExceptionHandled = true;
            filterContext.HttpContext.Response.Clear();
            //nothing is shown, since has been handled
            filterContext.HttpContext.Response.StatusCode = 500;
            // Http Status Code 500 should be used when and exception happens
            filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
            // Now use NLog to log above details to the Text Files.
            base.OnException(filterContext);
        }
        public override void OnException(ExceptionContext filterContext)
        {
            if (filterContext.ExceptionHandled || !filterContext.HttpContext.IsCustomErrorEnabled)
            {
                return;
            }

            if (new HttpException(null, filterContext.Exception).GetHttpCode() != 500)
            {
                return;
            }
            if (!ExceptionType.IsInstanceOfType(filterContext.Exception))
            {
                return;
            }
            //如果是AJAX请求返回json
            if (filterContext.HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest")
            {
                filterContext.Result = new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new
                    {
                        error   = true,
                        message = filterContext.Exception.Message
                    }
                };

                Log4NetHelper.GetLogger("AJAX-JSON").Error(filterContext.Exception.Message);
            }
            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(model),
                    TempData   = filterContext.Controller.TempData
                };
                Log4NetHelper.GetLogger(controllerName.ToString() + "-" + actionName.ToString()).Error(filterContext.Exception.Message);
            }

            filterContext.ExceptionHandled = true;
            filterContext.HttpContext.Response.Clear();
            filterContext.HttpContext.Response.StatusCode             = 500;
            filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
        }
示例#22
0
 // GET: Home
 public ActionResult Index()
 {
     try
     {
         HomeViewModel            model = new HomeViewModel();
         List <HotItemsViewModel> lst   = new List <HotItemsViewModel>();
         foreach (var item in Product.GetHotItems())
         {
             HotItemsViewModel hvm = new HotItemsViewModel()
             {
                 Id    = item.ProductId.ToString(),
                 Image = item.PrimaryImage,
                 Name  = item.Name
             };
             lst.Add(hvm);
         }
         model.HotItems = lst;
         List <FeaturedSunglassesViewModel> lstSunglasses = new List <FeaturedSunglassesViewModel>();
         foreach (var item in Sunglasses.FeaturedSunglasses())
         {
             FeaturedSunglassesViewModel fsvm = new FeaturedSunglassesViewModel()
             {
                 Id    = item.ProductId.ToString(),
                 Name  = item.Name,
                 Image = item.PrimaryImage,
                 Price = decimal.Round(item.Price).ToString()
             };
             lstSunglasses.Add(fsvm);
         }
         model.PopSunglasses = lstSunglasses;
         List <FeaturedPrescriptionGlassesViewModel> lstPrescription = new List <FeaturedPrescriptionGlassesViewModel>();
         foreach (var item in PrescriptionGlasses.FeaturedPrescriptionGlasses())
         {
             FeaturedPrescriptionGlassesViewModel fpvm = new FeaturedPrescriptionGlassesViewModel()
             {
                 Id    = item.ProductId.ToString(),
                 Name  = item.Name,
                 Image = item.PrimaryImage,
                 Price = decimal.Round(item.Price).ToString()
             };
             lstPrescription.Add(fpvm);
         }
         model.PopPrescriptionGlasses = lstPrescription;
         return(View(model));
     }
     catch (Exception ex)
     {
         HandleErrorInfo error = new HandleErrorInfo(ex, "Home", "Index");
         return(RedirectToAction("Index", "Error", new { model = error }));
     }
 }
示例#23
0
        protected void Application_Error()
        {
            var ex = Server.GetLastError();

            try
            {
                var logger = ModuleLoader.DI.Get <ILog>(Constants.ServerLoggerName);
                logger.Error("Application_Error", ex);
            }
            catch (Exception exc)
            {
                exc = exc.InnerException;
            }

            var code = (ex is HttpException) ? (ex as HttpException).GetHttpCode() : 500;

            Server.ClearError();
            Response.Clear();
            Response.ContentType = "text/html";
            Response.StatusCode  = code;

            // Hack for GoDaddy Hosting
            Response.TrySkipIisCustomErrors = true;

            // if the request is AJAX return JSON else view.
            if (IsAjax())
            {
                var errorMsg = (ex != null ? ex.Message : string.Empty);
                errorMsg += (ex != null && ex.InnerException != null ? ex.InnerException.Message : string.Empty);
                errorMsg += (ex != null && ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message : string.Empty);
                Context.Session["JSON_ERROR_MESSAGE"] = errorMsg;

                Context.Response.Redirect("~/Error/AjaxResponse", false);
                return;
            }

            var model = new HandleErrorInfo(ex, "UNKNOWN", "UNKNOWN");

            if (code == 404)
            {
                var result = RenderRazorViewToString("~/Views/Error/PageNotFound.cshtml", "~/Views/Shared/_commonLayout.cshtml", model);

                Response.Write(result);
            }
            else
            {
                var result = RenderRazorViewToString("~/Views/Error/Index.cshtml", "~/Views/Shared/_commonLayout.cshtml", model);

                Response.Write(result);
            }
        }
示例#24
0
        public static void ErrorLogFileWrite(HandleErrorInfo errorInfo)
        {
            FileStream   fileStream   = null;
            StreamWriter streamWriter = null;

            try
            {
                string logFilePath = HttpContext.Current.Server.MapPath("~") + "ErrorHistory\\ErrorLog.txt";

                if (logFilePath.Equals(""))
                {
                    return;
                }

                #region Create the Log file directory if it does not exists
                DirectoryInfo logDirInfo  = null;
                FileInfo      logFileInfo = new FileInfo(logFilePath);
                logDirInfo = new DirectoryInfo(logFileInfo.DirectoryName);
                if (!logDirInfo.Exists)
                {
                    logDirInfo.Create();
                }
                #endregion Create the Log file directory if it does not exists

                if (!logFileInfo.Exists)
                {
                    fileStream = logFileInfo.Create();
                }
                else
                {
                    fileStream = new FileStream(logFilePath, FileMode.Append);
                }
                streamWriter = new StreamWriter(fileStream);
                streamWriter.WriteLine("------------------------------Date: " + DateTime.Now.ToString() + "--------------------------------");
                streamWriter.WriteLine("Controller: " + errorInfo.ControllerName);
                streamWriter.WriteLine("Action: " + errorInfo.ActionName);
                streamWriter.WriteLine("HttpCode: " + (errorInfo.Exception is HttpException ? ((HttpException)errorInfo.Exception).GetHttpCode() : 500).ToString());
                streamWriter.WriteLine("Error Message: " + errorInfo.Exception + Environment.NewLine);
            }
            finally
            {
                if (streamWriter != null)
                {
                    streamWriter.Close();
                }
                if (fileStream != null)
                {
                    fileStream.Close();
                }
            }
        }
示例#25
0
        public override void OnException(ExceptionContext filterContext)
        {
            //   You need to catch that exception
            //	○ Get the exception details such as exception type
            //	○ Exception message
            //	○ Any inner exception
            //	○ Stack trace
            //	○ Date time when exception happened
            //	○ For which user exception happened ?
            //	○ URL where the exception happened
            //	○ Browser which user is using when exception happened
            //² Log those exception, usually we log them in text files, sometimes Database but its rare
            //	○ We can use any popular 3rd party Logging Frameworks to log the exception
            //		§ Nlog
            //		§ SeriLog
            //		§ Log4net
            //	○ Download those from nuget
            //² Send emails when exception happens to the Development Team
            //² Always show a friendly error page to the user

            var controllerName = (string)filterContext.RouteData.Values["controller"];
            var actionName     = (string)filterContext.RouteData.Values["action"];

            //create a Model for HandleErrorInfo, which is already built-in in MVC
            var model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);

            var dateTimeExceptionHappened = DateTime.Now.TimeOfDay.ToString();
            var stackTrace       = filterContext.Exception.StackTrace;
            var exceptionMessage = filterContext.Exception.Message;
            var innerException   = filterContext.Exception.InnerException;

            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;
            //Http Status Code 500 should be used when an exception happens
            filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;

            //Now use NLog to log above details to the Text Files.
            //send out emails to the dev team
            //to send emails in C#, theres a popular libary called: mailkit.. download from nuget

            base.OnException(filterContext);
        }
示例#26
0
        public override void OnException(ExceptionContext filterContext)
        {
            if (filterContext.ExceptionHandled || !filterContext.HttpContext.IsCustomErrorEnabled)
            {
                return;
            }

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

            if (!ExceptionType.IsInstanceOfType(filterContext.Exception))
            {
                return;
            }

            // if the request is AJAX return JSON else view.
            if (filterContext.HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest")
            {
                filterContext.Result = new JsonResult {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new {
                        error   = true,
                        message = filterContext.Exception.Message
                    }
                };
            }
            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
                };
            }

            // log the error using log4net.
            FotoShoutUtils.Log.LogManager.Error(_logger, filterContext.Exception.ToString());

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

            filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
        }
示例#27
0
        protected override void OnException(ExceptionContext filterContext)
        {
            filterContext.ExceptionHandled = true;
            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   = @"~/Views/Shared/Error.cshtml",
                MasterName = @"~/Views/Shared/_Layout.cshtml",
                ViewData   = new ViewDataDictionary <HandleErrorInfo>(model)
            };
        }
        /// <summary>
        /// Returns an error model whenever an application exception was handled.
        /// </summary>
        public ActionResult Error(int statusCode, Exception exception)
        {
            if (exception.GetType() == typeof(HttpException))
            {
                exception = new HttpException("The page you requested does not exist!");
            }

            var model = new HandleErrorInfo(exception, "ErrorPage", "Error");

            Response.StatusCode = statusCode;
            ViewBag.StatusCode  = $"Error {statusCode}";

            return(View(model));
        }
        protected override void OnException(ExceptionContext filter)
        {
            Exception ex = filter.Exception;

            filter.ExceptionHandled = true;

            var model = new HandleErrorInfo(ex, "controller", "action");

            filter.Result = new ViewResult()
            {
                ViewName = "ErrorMessage",
                ViewData = new ViewDataDictionary(model)
            };
        }
示例#30
0
        public void OnException(ExceptionContext filterContext)
        {
            if (!filterContext.ExceptionHandled && filterContext.Exception is ArgumentOutOfRangeException)
            {
                HandleErrorInfo hd = new HandleErrorInfo()
                {
                    ExceptionText = filterContext.Exception.ToString(), ControllerName = filterContext.Controller.ToString()
                };
                hd.SaveException();

                filterContext.Result           = new RedirectResult("~/Content/ErrorPage.html");
                filterContext.ExceptionHandled = true;
            }
        }
        public void ConstructorSetsProperties()
        {
            // Arrange
            Exception exception = new Exception();
            string controller = "SomeController";
            string action = "SomeAction";

            // Act
            HandleErrorInfo viewData = new HandleErrorInfo(exception, controller, action);

            // Assert
            Assert.Same(exception, viewData.Exception);
            Assert.Equal(controller, viewData.ControllerName);
            Assert.Equal(action, viewData.ActionName);
        }