src/AspNetCore/src/XperienceStatusCodePagesExtensions.cs
/// <summary> Adds a StatusCodePages middleware to the pipeline. Specifies that the response body should be generated by re-executing the request pipeline using a document in the Xperience Content Tree. </summary>
/// <remarks> The following implementation was adapted from the <see href="https://github.com/dotnet/aspnetcore/blob/e79d740ba95a1b1486e81aebace8d38ba06d35b9/src/Middleware/Diagnostics/src/StatusCodePage/StatusCodePagesExtensions.cs#L167">the source implementation</see> of the <see cref="StatusCodePagesExtensions.UseStatusCodePagesWithReExecute(IApplicationBuilder, string, string)"/> extension provided by the AspNetCore Mvc Framework. </remarks>
Adds a StatusCodePages middleware to the pipeline. Specifies that the response body should be generated by re-executing the request pipeline using a document in the Xperience Content Tree.
Adds a StatusCodePages middleware to the pipeline . Specifies that the response body should be generated by re - executing the request pipeline using a document in the Xperience Content Tree .
public static IApplicationBuilder UseXperienceStatusCodePagesWithReExecute( this IApplicationBuilder app )
        {
            if( app == null )
            {
                throw new ArgumentNullException( nameof( app ) );
            }
            return app.UseStatusCodePages(
                async context =>
                {
                    var path = await GetStatusCodePathAsync( context.HttpContext );
                    if( string.IsNullOrEmpty( path ) )
                    {
                        return;
                    }
                    var originalPath = context.HttpContext.Request.Path;
                    var originalQueryString = context.HttpContext.Request.QueryString;
                    context.HttpContext.Features.Set<IStatusCodeReExecuteFeature>(
                        new StatusCodeReExecuteFeature
                        {
                            OriginalPathBase = context.HttpContext.Request.PathBase.Value!,
                            OriginalPath = originalPath.Value!,
                            OriginalQueryString = originalQueryString.HasValue ? originalQueryString.Value : null,
                        }
                    );
                    context.HttpContext.SetEndpoint( endpoint: null );
                    var routeValuesFeature = context.HttpContext.Features.Get<IRouteValuesFeature>();
                    routeValuesFeature?.RouteValues?.Clear();
                    context.HttpContext.Request.Path = path;
                    context.HttpContext.Request.QueryString = QueryString.Empty;
                    try
                    {
                        await context.Next( context.HttpContext );
                    }
                    finally
                    {
                        context.HttpContext.Request.QueryString = originalQueryString;
                        context.HttpContext.Request.Path = originalPath;
                        context.HttpContext.Features.Set<IStatusCodeReExecuteFeature>( null );
                    }
                }
            );
        }
public static IApplicationBuilder UseXperienceStatusCodePagesWithReExecute ( this IApplicationBuilder app ) { if ( app == null ) { throw new ArgumentNullException ( nameof ( app ) ) ; } return app . UseStatusCodePages ( async context => { var path = await GetStatusCodePathAsync ( context . HttpContext ) ; if ( string . IsNullOrEmpty ( path ) ) { return ; } var originalPath = context . HttpContext . Request . Path ; var originalQueryString = context . HttpContext . Request . QueryString ; context . HttpContext . Features . Set < IStatusCodeReExecuteFeature > ( new StatusCodeReExecuteFeature { OriginalPathBase = context . HttpContext . Request . PathBase . Value ! , OriginalPath = originalPath . Value ! , OriginalQueryString = originalQueryString . HasValue ? originalQueryString . Value : null , } ) ; context . HttpContext . SetEndpoint ( endpoint : null ) ; var routeValuesFeature = context . HttpContext . Features . Get < IRouteValuesFeature > ( ) ; routeValuesFeature ? . RouteValues ? . Clear ( ) ; context . HttpContext . Request . Path = path ; context . HttpContext . Request . QueryString = QueryString . Empty ; try { await context . Next ( context . HttpContext ) ; } finally { context . HttpContext . Request . QueryString = originalQueryString ; context . HttpContext . Request . Path = originalPath ; context . HttpContext . Features . Set < IStatusCodeReExecuteFeature > ( null ) ; } } ) ; }
Adds a StatusCodePages middleware to the pipeline.
Adds a StatusCodePages middleware to the pipeline .
// Store the original paths so the app can check it. // An endpoint may have already been set. Since we're going to re-invoke the middleware pipeline we need to reset // the endpoint and route values to ensure things are re-calculated.
IApplicationBuilder
this
remarks
The following implementation was adapted from the the source implementation extension provided by the AspNetCore Mvc Framework.
The following implementation was adapted from the the source implementation extension provided by the AspNetCore Mvc Framework .