委托处理程序:删除“服务器”响应标头SelfHost API

时间:2017-04-26 07:24:27

标签: asp.net-web-api

response.Headers.Remove(“Server”)没有从响应中删除Server标头,仍然获得“Server - > Microsoft-HTTPAPI / 2.0”

 public class CustomHeaderHandler : DelegatingHandler
    {        
        protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
        {
            return base.SendAsync(request, cancellationToken)
                .ContinueWith((task) =>
                {
                    HttpResponseMessage response = task.Result;                                        
                    response.Headers.Remove("Server");                                       
                    return response;
                });
        }
    }

0 个答案:

没有答案