Ejemplo n.º 1
0
        protected override void OnEndRequest(HttpContextBase context)
        {
            var request  = context.Request;
            var response = context.Response;

            if (!response.StatusCode.Any((int)HttpStatusCode.InternalServerError, (int)HttpStatusCode.NotFound, (int)HttpStatusCode.Forbidden))
            {
                return;
            }

            if (request.RawUrl.Contains("favicon.ico"))
            {
                return;
            }

            string routeName;

            if (response.StatusCode == (int)HttpStatusCode.InternalServerError)
            {
                return;
            }

            switch (response.StatusCode)
            {
            case (int)HttpStatusCode.InternalServerError:
                routeName = RootSectionConstants.ErrorsController.GenericError.RouteName;
                break;

            case (int)HttpStatusCode.NotFound:
                routeName = RootSectionConstants.ErrorsController.NotFound.RouteName;
                break;

            default:
                routeName = RootSectionConstants.ErrorsController.AccessDenied.RouteName;
                break;
            }

            var url = RouteUrlProvider.GetUrl(routeName);

            if (request.RawUrl.StartsWith(url))
            {
                return;
            }

            response.Clear();

            response.TrySkipIisCustomErrors = true;

            url = RouteUrlProvider.GetUrl(routeName, RouteParameter.Add("url", request.RawUrl));

            response.Redirect(url);
        }
Ejemplo n.º 2
0
        protected string FormatOrRenewParameter(ControllerContext controllerContext, string then)
        {
            if (string.IsNullOrWhiteSpace(then))
            {
                return(RouteUrlProvider.GetUrl(RootSectionConstants.CommonController.Home.RouteName));
            }

            then = controllerContext.RequestContext.HttpContext.Server.UrlDecode(then);

            foreach (var parameterName in ParameterNames)
            {
                var indexOfThen = then.IndexOf(parameterName + "=");

                while (indexOfThen > 0)
                {
                    indexOfThen += parameterName.Length + 1;
                    then         = then.Substring(indexOfThen, then.Length - indexOfThen);

                    indexOfThen = then.IndexOf(parameterName + "=");
                }
            }

            return(then);
        }