Asp.net web api 委托处理程序:删除";服务器";响应头SelfHost API
response.Headers.Remove(“服务器”)没有从响应中删除服务器头,仍然获得“服务器-->Microsoft HTTPAPI/2.0”Asp.net web api 委托处理程序:删除";服务器";响应头SelfHost API,asp.net-web-api,Asp.net Web Api,response.Headers.Remove(“服务器”)没有从响应中删除服务器头,仍然获得“服务器-->Microsoft HTTPAPI/2.0” 公共类CustomHeaderHandler:DelegatingHandler { 受保护的覆盖任务SendAsync(HttpRequestMessage请求,System.Threading.CancellationToken CancellationToken) { return base.sendaync(请求、取消令
公共类CustomHeaderHandler:DelegatingHandler
{
受保护的覆盖任务SendAsync(HttpRequestMessage请求,System.Threading.CancellationToken CancellationToken)
{
return base.sendaync(请求、取消令牌)
.ContinueWith((任务)=>
{
HttpResponseMessage response=task.Result;
response.Headers.Remove(“服务器”);
返回响应;
});
}
}
尝试为IOwinResponse.OnSendingHeaders
事件注册回调:我正在使用HttpSelfHostServer托管服务,而不是使用startup类或IAppbuilder。var config=WcfimConfig.InitializeConfiguration(基本地址);Add(waim.GetHttpProviderHandler());waim.RegisterHttpConfig(配置);HttpSelfHostServer服务器=新的HttpSelfHostServer(配置);
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;
});
}
}