从响应删除头 [英] Removing headers from the response

查看:136
本文介绍了从响应删除头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一件披风ASP.NET和IIS产生一定的头,并在从ASP.NET的WebAPI服务的响应返回。我要披风的标题是:

I need to cloak certain headers generated by ASP.NET and IIS and returned in the responses from a ASP.NET WebAPI service. The headers I need to cloak are:


  • 服务器

  • X-ASPNET-版本

  • X-AspNetMvc-版本

  • X-技术,通过

这项服务是在WCF中较早主办,隐形是通过订阅preSendRequestHeaders和操纵HttpContext.Current.Response.Headers在一个HttpModule完成。使用ASP.NET的WebAPI的一切现在是基于任务的,所以HttpContext.Current为null。我试图插入一个消息处理程序和处理返回的Htt presponseMessage,但头部没有那个舞台上present。的X技术,通过可在IIS设置中删除,但什么是建议的方法,以消除他们的休息?

The service was earlier hosted in WCF, and the cloaking was done in an HttpModule by subscribing to PreSendRequestHeaders and manipulating HttpContext.Current.Response.Headers. With ASP.NET WebAPI everything is now task based, so HttpContext.Current is null. I tried to insert a message handler and manipulate the returned HttpResponseMessage, but the headers were not present on that stage. X-Powered-By can be removed in the IIS settings, but what is the suggested way to remove the rest of them?

推荐答案

问题是每个人在不同的点加:

The problem is each one is added at a different point:


  • 服务器:由IIS添加。不完全相信,如果它可以被关闭,尽管你似乎一直使用的HttpModule将其删除。

  • X-ASPNET-版本:在冲洗时通过添加System.Web.dll的的Htt presponse

  • X-AspNetMvc-版本:在System.Web.dll中添加由 MvcHandler 。它可以覆盖所以这一块应该没问题。

  • X-技术,通过通过IIS,但可以如你所说被关闭。

  • Server: added by IIS. Not exactly sure if it can be turned off although you seem to have been to remove it using HttpModule .
  • X-AspNet-Version: added by System.Web.dll at the time of Flush in HttpResponse class
  • X-AspNetMvc-Version: Added by MvcHandler in System.Web.dll. It can be overridden so this one should be OK.
  • X-Powered-By by IIS but can be turned off as you said.

我觉得你最好的选择仍然使用的HttpModules。

I think your best bet is still using HttpModules.

这篇关于从响应删除头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆