以编程方式从配置数据库 IIS6 中删除 etag 后缀(更改编号)

发布于 2024-07-22 11:52:03 字数 1338 浏览 5 评论 0原文

IIS 6.0 以“hash:changenumber”格式生成 eTag 值。 每次 IIS 重置时,更改编号都会增加,因此您的 eTag 仅在 IIS 进程的生命周期内有效。 重启,number上升,hash:changenumber != hash:changenumber+1。

解决此问题的方法是对更改号进行硬编码,这可以使用元数据库资源管理器来实现,一个 .NET 实用程序,用于编辑元数据库,或在 IIS 服务停止时编辑 XML 文件。

我想在服务器运行的情况下以编程方式执行此操作,就像我可以使用 ADSI 或 WMI 设置所有其他元数据库属性一样。 对于这一点,这似乎不可能,因为该属性(仅在内部称为 MD_ETAG_CHANGENUMBER)似乎没有匹配的属性名称。

以下是 VBScript 中问题的示例:

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

输出:

日志类型:1 
  etag.vbs(3, 1) Microsoft VBScript 运行时错误:对象不支持此属性或方法:“obj.MD_ETAG_CHANGENUMBER” 
  

我希望能够在 C# 中设置这个值。 除了停止 IIS、在 XML 中设置值并重新启动它之外,是否有一种以编程方式设置此值的方法?

我最好的想法是(ab)使用Metabase Explorer 附带的IISMbLib.dll,所以如果有人有使用它的经验,我很乐意听到它。

参考文献:

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:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

中性美 2024-07-29 11:52:04

我最好的想法是相当不错。 下面是一个解决方案,它依赖于 IIS 6.0 资源工具包中 Metabase Explorer 中的 IISMbLib.dll。

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

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);
        }
ヅ她的身影、若隐若现 2024-07-29 11:52:03

crb,感谢您提供了出色的解决方案,我无法找到替代方案(尽管我之前已通过自定义 ISAPI 使用的一些棘手的 ADSI 脚本将我自己的自定义配置数据库属性添加到 IIS 6 架构中)

这是一个 powershell 版本您的解决方案。 它假定 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)

crb, thanks for the great solution, I was unable to find an alternative (although I have previously added my own custom metabase properties to the IIS 6 schema through some tricky ADSI scripting, that are used by a custom ISAPI)

Here is a powershell version of your solution. It assumes MB Explorer assembly copied locally to it.

$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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文