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:
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:
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
classX-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.I think your best bet is still using HttpModules.