.net core实现一个添加header的过滤器
电脑版发表于:2020/12/8 16:57
过滤器:
public class AddHeaderAttribute : ResultFilterAttribute { private readonly string _name; private readonly string _value; public AddHeaderAttribute(string name, string value) { _name = name; _value = value; } public override void OnResultExecuting(ResultExecutingContext context) { context.HttpContext.Response.Headers.Add(_name, new string[] { _value }); base.OnResultExecuting(context); } }
使用:
[AddHeader("Auhtor", "XKA")] public IActionResult Index() { return View(); }