Remove the X-AspNet-Version header

Jun 18, 2007

I’ve always been a little annoyed by the fact that ASP.NET websites sends the version number as a HTTP header. For an ASP.NET 2.0 application this is added automatically to the headers and you cannot remove it from code. This is what it looks like:

X-AspNet-Version => 2.0.50727

Why would it be necessary to send this information about your application to possible hackers? It doesn’t make sense. Maybe it’s because it allows for statistics to be collected about what versions people are using. Microsoft could then send a crawler to investigate all the websites in the Windows Live search database. I don’t have a problem with that; it’s the hackers I fear.

The other auto-injected header X-Powered-By => ASP.NET is fine with me. It’s easy for people to see by the .aspx extension that you run ASP.NET anyway, so this is not a security issue but still a little annoying that you cannot remove it from within your ASP.NET application. You have to remove it from the IIS.

Then the other day I was playing around with the web.config and by accident noticed the httpRuntime tag and its enableVersionHeader attribute. For some reason I’ve never noticed it before. If the enableVersionHeader attribute is set to false, the X-AspNet-Version header will not be sent.

So, to get rid of the X-AspNet-Version HTTP header from the response, just copy this line into the web.config’s <system.web> section:

<httpRuntime enableVersionHeader="false" />

I think if it was such a big deal to get rid of it, I’d probably done some more research and found this trick years ago. Anyway, I just thought I would share it with you.

To check the HTTP headers sent from your own site, you can use one of the many online tools like this one.

* Only $4.95/month ASP.NET & Windows 2008 + IIS 7 Hosting! FREE SQL Included

Comments (5) -

Patrick
Patrick United States
6/19/2007 12:11:16 PM #

That is a really good tip.  I know that you shouldn't do security by obscurity, but the engine should give itself away SO easily.

Paul Wilson
Paul Wilson United States
6/19/2007 12:15:31 PM #

Nice tip -- thanks for sharing it.

Josh Stodola
Josh Stodola United States
6/19/2007 12:22:46 PM #

That is a great tip definitely worth sharing - thanks alot.  I have also been annoyed with that useless header, and now I have yet another reason to avoid opening IIS Smile

dave thieben
dave thieben United States
6/19/2007 8:11:06 PM #

or pop it into machine.config and forget about it.

Turd Fergusson
Turd Fergusson
7/8/2008 1:12:54 AM #

An alternative to view the HTTP headers of a web site is to use cURL (a *nix command line tool available for just about every OS out there):

curl -Ik http://www.google.com

If you prefer to use a command line tool vs a webpage.  This is useful for doing internal testing prior to sending a site to production.

Pingbacks and trackbacks (1)+

Comments are closed

About the author

Mads Kristensen

Mads Kristensen
Program Manager at the Microsoft Web Platform team and founder of BlogEngine.NET.

More...

Month List

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way.