You can write a custom attribute to handle this scenario:
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public sealed class SuppressHeadersAttribute : ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
//suppress headers here
//filterContext has access to the HttpContext
}
}
Then have the controllers that you need to follow this patter inherit from a base controller that has this attribute.
[SuppressHeader]
public class BaseController : Controller
{
}
public class YourController : BaseController
{
//Do Stuff
}
Using this you can suppress the headers on only the things that need it.