// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc.Filters; namespace Microsoft.AspNetCore.Mvc { /// /// Filter to prevent StatusCodePages middleware to handle responses. /// [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] public class SkipStatusCodePagesAttribute : Attribute, IResourceFilter { /// public void OnResourceExecuted(ResourceExecutedContext context) { } /// public void OnResourceExecuting(ResourceExecutingContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var statusCodeFeature = context.HttpContext.Features.Get(); if (statusCodeFeature != null) { // Turn off the StatusCodePages feature. statusCodeFeature.Enabled = false; } } } }