Programmatically remove etag suffix (change number) from IIS6 metabase

IIS 6.0 generates eTag values ​​in the format "hash: changenumber". The changing number increases every time IIS is reset, so your eTag is only valid for the life of your IIS process. Restart, number increases, hash: changenumber! = Hash: changenumber + 1.

Fix this to hard-code the changenumber , which is possible with Metabase Explorer, the .NET utility for editing the metabase, or by editing the XML file when IIS is stopped.

I want to do this programmatically, with the server running, for example, I can set all other metabase properties using ADSI or WMI. This is not possible for this, since the property (which is only internally called MD_ETAG_CHANGENUMBER) does not seem to have a corresponding property name.

Here is an example of a problem in VBScript:

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

Exit:

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 #. If you don't stop IIS by setting the value in XML and running it again, is there a way to program this value programmatically?

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

Literature:

+3
2

. , IISMbLib.dll Metabase Explorer IIS 6.0.

        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);
        }
+1

crb, , ( ​​ IIS 6 ADSI, ISAPI)

. , MB Explorer .

$myPath = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path)

Import-Module "$myPath\IISMbLib.dll"

$etagValue = 12345
$metabase = New-Object IISConfig.Metabase
$metabase.OpenLocalMachine()

$key = $metabase.GetKeyFromPath("/LM/W3SVC")

if ($key.ContainsRecord(2039) -eq [IISConfig.ValueExistOptions]::Explicit)
{
    $record = $key.GetRecord(2039)
    Write-Host "Existing ETag value found:", $record.Data.ToString()
}
else
{
    Write-Host "Creating new value..."
    $record = New-Object IISConfig.Record
    $record.DataType = [IISConfig.Record+DataTypes]::DWORD
    $record.Identifier = 2039
    $record.ChangeAttribute([IISConfig.Record+AttributeList]::Inherit, $true)
}
$record.Data = [System.Convert]::ToUInt32($etagValue)
Write-Host "New ETag value:", $record.Data.ToString()
$key.SetRecord($record)
+2

Source: https://habr.com/ru/post/1709320/


All Articles