新的Web API 2.0项目,因此我们可以完全控制整个请求/响应管道。
如何从ASP.NET Web API response发送的响应中删除"X-“头?具体地说,我们希望删除"X-AspNet-Version“、"X-Powered-By”和"X-SourceFiles“。
在从控制器返回HttpResponseMessage之前,我们尝试了result.Headers.Remove("X-AspNet-Version");。这不起作用,因为标题仍然出现在Fiddler中。我在HttpResponseMessage对象上也找不到任何头文件。对
简单请求是满足以下条件的请求:
HTTP方法匹配(区分大小写)之一:
- HEAD
- GET
- POST
HTTP头匹配(不区分大小写):
- Accept
- Accept-Language
- Content-Language
- Last-Event-ID
- Content-Type, but only if the value is one of:
- application/x-www-form-urlencoded
- multipart/form-data
- text/plain
但是看看这个,它不会引起
我有一台IIS 10.0服务器,我看到一些不允许的头文件Pragma,Expires仍在添加,但它们只被添加到API端点,而不是在检索静态内容时添加。这些标头未在代码中设置。我遵循了HTTP (将remove元素添加到configuration\system.webServer\httpProtocol\customHeaders),中),在调试时,在将其发送回调用者之前,我在recommended approach to remove the headers from IIS响应中看不到这些头。我想从响应中删除这些标头,但不知道如何确定它们被设置在哪里。有什么建议吗?
我使用angular2-http(alpha.44)模块从REST Api中检索数据。我不知道如何访问响应的头映射中的信息,我需要一个特定的字段。示例:
var req = new Request({
url: `localhost/api/products`,
method: RequestMethods.Get
});
this.http.request(req).subscribe(
res => {
// Can't access the headers of the response here.... res.headers is empty