コード例 #1
0
        public async Task <IActionResult> Status404()
        {
            try
            {
                // Look for a redirect for the requested URL
                var requestFeature       = HttpContext.Features.Get <IHttpRequestFeature>();
                var absoluteRequestedUrl = new Uri(new Uri(Request.GetDisplayUrl()), new Uri(requestFeature.RawTarget, UriKind.Relative));
                absoluteRequestedUrl = _notFoundRequestPathResolver?.NormaliseRequestedPath(absoluteRequestedUrl);

                var redirect = _redirectMatcher?.MatchRedirect(absoluteRequestedUrl);
                if (redirect != null)
                {
                    redirect = _convertToAbsoluteUrlHandler?.HandleRedirect(redirect) ?? redirect;
                    redirect = _preserveQueryStringHandler?.HandleRedirect(redirect) ?? redirect;
                    Response.Headers.Add("X-ESCC-Redirect", redirect.RedirectId.ToString());
                    Response.Headers.Add("Location", redirect.DestinationUrl.ToString());
                    return(new StatusCodeResult(redirect.StatusCode));
                }
            }
            catch (Exception ex)
            {
                // If there's a problem with redirects, publish the error and continue to show 404 page
                ex.ToExceptionless().Submit();
            }

            // If no redirects matched, show the 404 page
            var model = new HttpStatusViewModel(_defaultModelValues)
            {
                TemplateHtml = await _templateRequest.RequestTemplateHtmlAsync(),
                RequestId    = Activity.Current?.Id ?? HttpContext?.TraceIdentifier
            };

            return(View("~/_EastSussexGovUK_HttpStatus_NotFound.cshtml", model));
        }
コード例 #2
0
        public async Task <IActionResult> Status410()
        {
            var model = new HttpStatusViewModel(_defaultModelValues)
            {
                TemplateHtml = await _templateRequest.RequestTemplateHtmlAsync(),
                RequestId    = Activity.Current?.Id ?? HttpContext?.TraceIdentifier
            };

            return(View("~/_EastSussexGovUK_HttpStatus_Gone.cshtml", model));
        }
コード例 #3
0
        public async Task <IActionResult> Status500()
        {
            RandomDelay();

            var exceptionHandlerPathFeature = HttpContext?.Features.Get <IExceptionHandlerPathFeature>();

            exceptionHandlerPathFeature?.Error?.ToExceptionless().Submit();

            var model = new HttpStatusViewModel(_defaultModelValues)
            {
                TemplateHtml = await _templateRequest.RequestTemplateHtmlAsync(),
                RequestId    = Activity.Current?.Id ?? HttpContext?.TraceIdentifier
            };

            return(View("~/_EastSussexGovUK_HttpStatus_InternalServerError.cshtml", model));
        }