views:

692

answers:

1

IIS 6.0 generates eTag values in the format of "hash:changenumber". The changenumber goes up every time IIS resets, so your eTag is only valid for the lifetime of your IIS process. Restart, number goes up, hash:changenumber != hash:changenumber+1.

The fix for this is to hard-code the changenumber, which is possible using the Metabase Explorer, a .NET utility for editing the metabase, or by editing the XML file when the IIS services are stopped.

I want to do this programmatically, with the server running, like I can set all the other metabase properties with either ADSI or WMI. For this one it doesn't seem to be possible, as the property (which is only internally referred to as MD_ETAG_CHANGENUMBER) does not appear to have a matching property name.

Here's an example of the problem in VBScript:

set obj=GetObject("IIS://localhost/W3svc")
WScript.Echo "Log type: " & obj.LogType
WScript.Echo "Change number: " & obj.MD_ETAG_CHANGENUMBER

The output:

Log type: 1
etag.vbs(3, 1) Microsoft VBScript runtime error: Object doesn't support this property or method: 'obj.MD_ETAG_CHANGENUMBER'

I want to be able to set this value in C#. Short of stopping IIS, setting the value in the XML, and starting it again, is there a method of setting this value programatically?

My best thought is (ab)using the IISMbLib.dll that comes with Metabase Explorer, so if anyone has experience using this, I'd love to hear it.

References:

A: 

My best thought was pretty good. Here is a solution, which depends on IISMbLib.dll from the Metabase Explorer in the IIS 6.0 Resource Kit.

        Metabase metabase = new Metabase();
        metabase.OpenLocalMachine();

        IKey key = metabase.GetKeyFromPath("/LM/W3SVC/");
        if (key.ContainsRecord(2039) == IISConfig.ValueExistOptions.Explicit) {
            Record r = key.GetRecord(2039);
            r.Data = Convert.ToUInt32(0);
            key.SetRecord(r);
        } else {
            Record r = new Record();
            r.Data = Convert.ToUInt32(0);
            r.DataType = Record.DataTypes.DWORD;
            r.Identifier = 2039;
            r.ChangeAttribute(Record.AttributeList.Inherit, true);
            key.SetRecord(r);
        }
crb