File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
dotnet/src/dotnetcore/GxNetCoreStartup Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -503,9 +503,11 @@ bool IsAspx(HttpContext context, string basePath)
503503 }
504504 public class CustomExceptionHandlerMiddleware
505505 {
506+ const string InvalidCSRFToken = "InvalidCSRFToken" ;
506507 static readonly ILog log = log4net . LogManager . GetLogger ( typeof ( CustomExceptionHandlerMiddleware ) ) ;
507508 public async Task Invoke ( HttpContext httpContext )
508509 {
510+ string httpReasonPhrase = string . Empty ;
509511 Exception ex = httpContext . Features . Get < IExceptionHandlerFeature > ( ) ? . Error ;
510512 HttpStatusCode httpStatusCode = ( HttpStatusCode ) httpContext . Response . StatusCode ;
511513 if ( ex != null )
@@ -519,6 +521,7 @@ public async Task Invoke(HttpContext httpContext)
519521 {
520522 //"The required antiforgery header value "X-GXCSRF-TOKEN" is not present.
521523 httpStatusCode = HttpStatusCode . BadRequest ;
524+ httpReasonPhrase = InvalidCSRFToken ;
522525 GXLogging . Error ( log , $ "Validation of antiforgery failed", ex ) ;
523526 }
524527 else
@@ -538,6 +541,12 @@ public async Task Invoke(HttpContext httpContext)
538541 {
539542 httpContext . Response . StatusCode = ( int ) httpStatusCode ;
540543 }
544+ if ( ! string . IsNullOrEmpty ( httpReasonPhrase ) )
545+ {
546+ IHttpResponseFeature responseReason = httpContext . Response . HttpContext . Features . Get < IHttpResponseFeature > ( ) ;
547+ if ( responseReason != null )
548+ responseReason . ReasonPhrase = httpReasonPhrase ;
549+ }
541550 }
542551 await Task . CompletedTask ;
543552 }
You can’t perform that action at this time.
0 commit comments