I’m trying to find a way to have ETag with a blank value as I did in IIS6. The reason for this is website optimisation. A great place for this is http://webpagetest.org

However the problem I’m having is that IIS7 doesn’t allow a blank value to be entered in to the HTTP Headers value box.

I’ve just come from another site – which will remain nameless and one of their ‘experts‘ suggested using double quotes “” in the value – which doesn’t actually work.

I tried ETag and a value of “” and it just simply doesn’t work. Does anyone have a suggestion that actually does? …One that they might have actually tried or maybe even have tested before posting a reply?

I could also set my YSlow to not display the ETag problem, but it’s not about what I see, it’s what other website tune-up sites see. Simply ignoring them won’t make the problem go away – a bit like just putting my head in a paper bag…

In IIS6 one could put an ETag in the HTTP headers and then leave the value blank, but in IIS7 it’s impossible to have a blank value. It’s almost as though Microsoft are doing everything they can to spite system admins, stop all forms of optimization whilst simultaneously disabling as much functionality as they can.

Well I must say I’m really looking forward to IIS -8, that will probably just be a command prompt with a flashing cursor that crashes the system every five minutes – It’s nice to know that the programmers at Microsoft are trying to lock-in as much un-adjustable bad configuration as possible and programmed in such a way as only Microsoft know how… I think they’re running at about 5 critical security flaws for every one line of code…

IIS7 Solution – Thanks to Kristofer Gafvert

The compiled module is here:

http://www.it-notebook.org/temp/removeetag.zip

To install:

In the root folder of your website, create a folder called “BIN” (if it is not already there). Copy the dll-file to this folder.

In IIS Manager, go to the website, and select “Modules”. Click “Add Managed Modules”.

Name: RemoveETag
Type: org.it_notebook.RemoveETagModule

It should be enabled immediately, and you can test if it removes the ETag header. I tested, and it worked fine on my machine.

 

This code also removes cookies, but only for files with the .htm extension

using System.Web;
using System.IO;

namespace org.it_notebook
{
    public class RemoveETagModule : IHttpModule
    { 
        int removeCookie = 0;

		public void Dispose() { } 

		public void Init(HttpApplication context)
        {
            context.PreSendRequestHeaders += OnPreSendRequestHeaders;
			context.PreRequestHandlerExecute += new EventHandler(OnPreRequestHandlerExecute);
        } 

        void OnPreSendRequestHeaders(object sender, EventArgs e)
        {
			HttpContext.Current.Response.Headers.Remove("ETag");
			if (removeCookie == 1)
			{
				HttpContext.Current.Response.Headers.Remove("Set-Cookie");
			}
        }

		public void OnPreRequestHandlerExecute (Object source, EventArgs e)
		{
			String url = HttpContext.Current.Request.FilePath.ToString();			
			String ext = Path.GetExtension(url);
			if( ext == ".htm")
			{
				removeCookie = 1;
			}

		}
    }
}

0 comments

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>