Пример #1
0
        protected void Application_Error(object sender, EventArgs e)
        {
            // Skip error processing if debugging
            if (HttpContext.Current.IsDebuggingEnabled)
            {
                return;
            }

            Exception exception = Server.GetLastError();

            HttpException httpException = exception as HttpException;

            Elmah.ErrorSignal.FromCurrentContext().Raise(exception);

            if (httpException != null)
            {
                string action = null;

                switch (httpException.GetHttpCode())
                {
                case 404:
                    // page not found
                    action = "NotFound";
                    break;

                case 500:
                    // server error
                    action = "Index";
                    break;
                }

                if (!string.IsNullOrEmpty(action))
                {
                    // clear error on server
                    Response.Clear();
                    Server.ClearError();
                    Response.TrySkipIisCustomErrors = true;

                    // Call target Controller and pass the routeData.
                    IController errorController = new BeYourMarket.Web.Controllers.ErrorController();
                    var         routeData       = new RouteData();
                    routeData.Values.Add("controller", "Error");
                    routeData.Values.Add("action", action);

                    errorController.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));
                }
            }
        }
Пример #2
0
        protected void Application_Error(object sender, EventArgs e)
        {
            // Skip error processing if debugging
            if (HttpContext.Current.IsDebuggingEnabled)
                return;

            Exception exception = Server.GetLastError();

            HttpException httpException = exception as HttpException;

            Elmah.ErrorSignal.FromCurrentContext().Raise(exception);

            if (httpException != null)
            {
                string action = null;

                switch (httpException.GetHttpCode())
                {
                    case 404:
                        // page not found
                        action = "NotFound";
                        break;
                    case 500:
                        // server error
                        action = "Index";
                        break;
                }

                if (!string.IsNullOrEmpty(action))
                {
                    // clear error on server
                    Response.Clear();
                    Server.ClearError();
                    Response.TrySkipIisCustomErrors = true;

                    // Call target Controller and pass the routeData.
                    IController errorController = new BeYourMarket.Web.Controllers.ErrorController();
                    var routeData = new RouteData();
                    routeData.Values.Add("controller", "Error");
                    routeData.Values.Add("action", action);

                    errorController.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));
                }
            }
        }