Beispiel #1
0
        internal static bool ServeCustomPageNotFoundPage(HttpContext httpContext)
        {
            string rawUrl = httpContext.Request.RawUrl;

            string customPageNotFoundUrl = HostnameBindingsFacade.GetCustomPageNotFoundUrl();

            if (string.IsNullOrEmpty(customPageNotFoundUrl))
            {
                return(false);
            }

            if (rawUrl == customPageNotFoundUrl || httpContext.Request.Url.PathAndQuery == customPageNotFoundUrl)
            {
                throw new HttpException(404, "'Page not found' wasn't handled. Url: '{0}'".FormatWith(rawUrl));
            }

            if (HttpRuntime.UsingIntegratedPipeline && customPageNotFoundUrl.StartsWith("/"))
            {
                httpContext.Server.TransferRequest(customPageNotFoundUrl);
                return(true);
            }

            httpContext.Response.Redirect(customPageNotFoundUrl, true);

            throw new InvalidOperationException("This code should not be reachable");
        }
Beispiel #2
0
        internal static bool IsPageNotFoundRequest()
        {
            HttpContext context = HttpContext.Current;

            if (context == null)
            {
                return(false);
            }

            string customPageNotFoundUrl = HostnameBindingsFacade.GetCustomPageNotFoundUrl();

            if (customPageNotFoundUrl.IsNullOrEmpty())
            {
                return(false);
            }

            customPageNotFoundUrl = customPageNotFoundUrl.Trim();

            if (!customPageNotFoundUrl.StartsWith("/") && !customPageNotFoundUrl.Contains("://"))
            {
                customPageNotFoundUrl = "/" + customPageNotFoundUrl;
            }

            var request = context.Request;

            return(request.RawUrl == customPageNotFoundUrl ||
                   request.Url.PathAndQuery == customPageNotFoundUrl ||
                   request.Url.PathAndQuery.StartsWith(customPageNotFoundUrl + "?"));
        }
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            var httpContext = HttpContext.Current;

            if (!HostnameBindingsFacade.ServeCustomPageNotFoundPage(httpContext))
            {
                throw new InvalidOperationException("Failed to redirect to 'page not found' url");
            }

            return(EmptyHttpHandler.Instance);
        }
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            // Skipping the route is there's no associated "Page not found" url
            if (string.IsNullOrEmpty(HostnameBindingsFacade.GetCustomPageNotFoundUrl()))
            {
                return(null);
            }

            // Skipping root request
            if (httpContext.Request.RawUrl.Length == UrlUtils.PublicRootPath.Length + 1)
            {
                return(null);
            }

            return(base.GetRouteData(httpContext));
        }