排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术
分类:
.net core
添加 HTTP 标头的结果筛选器
public class AddHeaderResultServiceFilter : IResultFilter { private ILogger _logger; public AddHeaderResultServiceFilter(ILoggerFactory loggerFactory) { _logger = loggerFactory.CreateLogger<AddHeaderResultServiceFilter>(); } public void OnResultExecuting(ResultExecutingContext context) { var headerName = "Author"; context.HttpContext.Response.Headers.Add( headerName, new string[] { "WXXK" }); _logger.LogInformation("Header added: {HeaderName}", headerName); } public void OnResultExecuted(ResultExecutedContext context) { } }
特性:
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); } }
评价