Is there any way to remove "Server" response header from IIS7? There are some articles showing that using HttpModules we can achieve the same thing. This will be helpful if we don't have admin right to server. Also I don't want to write ISAPI filter.
I have admin rights to my server. So I don't want to do the above stuff. So, please help me to do the same.
In IIS7 you have to use an HTTP module. Build the following as a class library in VS:
Then add the following to your web.config, or you configure it within IIS (if you configure within IIS, the assembly must be in the GAC).
Scott Mitchell provides in a blog post solutions for removing unnecessary headers.
As already said here in other answers, for the
Server
header, there is the http module solution or the UrlScan module. (URLScan module is no more available in IIS7.5+. Use URLRewrite instead for blanking it.)For
X-AspNet-Version
andX-AspNetMvc-Version
, he provides a better way than removing them on each response: simply not generating them at all.Use
enableVersionHeader
for disablingX-AspNet-Version
, in web.configUse
MvcHandler.DisableMvcResponseHeader
in .Net Application_Start event for disablingX-AspNetMvc-Version
And finally, remove in IIS configuration the
X-Powered-By
custom header.Do not forget that solution by application code does not apply by default to header generated on static content (you may activate the
runAllManagedModulesForAllRequests
for changing that, but it causes all requests to run .Net pipeline). It is not an issue forX-AspNetMvc-Version
since it is not added on static content (at least if static request are not run in .Net pipeline).Side note: when the aim is to cloak used technology, you should also change standard .Net cookie names (
.ASPXAUTH
if forms auth activated (usename
attribute onforms
tag in web.config),ASP.NET_SessionId
(use<sessionState cookieName="yourName" />
in web.config undersystem.web
tag),__RequestVerificationToken
(change it by code withAntiForgeryConfig.CookieName
, but unfortunately does not apply to the hidden input this system generates in the html)).Actually the coded modules and the Global.asax examples shown above only work for valid requests.
For example, add < on the end of your URL and you will get a "Bad request" page which still exposes the server header. A lot of developers overlook this.
The registry settings shown do not work either. URLScan is the ONLY way to remove the "server" header (at least in IIS 7.5).
I tried all of the stuff here and on several other similar stack overflow threads.
I got hung up for a bit because I forgot to clear my browser cache after making config changes. If you don't do that and the file is in your local cache, it will serve it back to you with the original headers (duh).
I got it mostly working by removing the runAllManagedModulesForAllRequests:
This removed the extraneous headers from most of the static files but I still was getting the "Server" header on some static files in my WebAPI project in swagger.
I finally found and applied this solution and now all of the unwanted headers are gone:
https://www.dionach.com/blog/easily-remove-unwanted-http-headers-in-iis-70-to-85
which discusses his code that is here:
https://github.com/Dionach/StripHeaders/releases/tag/v1.0.5
This is a Native-Code module. It is able to remove the Server header, not just blank out the value. By default it removes:
Add this to your global.asax.cs:
I had researched this and the URLRewrite method works well. Can't seem to find the change scripted anywhere well. I wrote this compatible with PowerShell v2 and above and tested it on IIS 7.5.