Например, мне нужно отобразить страницу 404.cshtml, но мне нужно изменить ответ.StatusCode = 400 вместо 404.
Во время построения конвейера я делаю следующее:
Код: Выделить всё
app
.Use( async ( context, next ) => {
if ( new[] { 500, 401, 403, 404 }.Contains( context.Response.StatusCode ) )
{
Console.WriteLine( $"app.Use (before) StatusCode: {context.Response.StatusCode}, {context.Request.Path}" );
}
await next();
} )
.UseExceptionHandler( "/errors/handler" )
.UseStatusCodePagesWithReExecute( "/errors/{0}" );
// register more middlewares, one which could return 404, psuedo is below...
app.Use( async ( context, next ) =>
{
if ( context.Request.Path.StartsWithSegments( "/app/channel-homex" ) )
{
context.Response.StatusCode = 404;
return;
}
await next();
} ).Use( async ( context, next ) =>
{
if ( new[] { 500, 401, 403, 404 }.Contains( context.Response.StatusCode ) )
{
Console.WriteLine( $"app.Use (after) StatusCode: {context.Response.StatusCode}, {context.Request.Path}" );
}
await next();
} );
Я неправильно понимаю конвейеры или то, как обрабатывать return и await next() в моих реализациях промежуточного программного обеспечения?
Подробнее здесь: https://stackoverflow.com/questions/787 ... line-again
Мобильная версия