以编程方式从配置数据库IIS6中删除etag后缀(更改号) [英] Programatically removing etag suffix (change number) from the metabase IIS6

查看:257
本文介绍了以编程方式从配置数据库IIS6中删除etag后缀(更改号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IIS 6.0生成 hash:changenumber格式的eTag值。每次IIS重置,更改号都会增加,因此您的eTag仅在IIS进程的生命周期内有效。重新启动,数字增加,hash:changenumber!= hash:changenumber + 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.

解决此问题的方法是硬编码更改号,这可以使用Metabase Explorer(一种用于编辑配置数据库的.NET实用工具)或在IIS服务已停止。

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.

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

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.

这是VBScript中问题的一个示例:

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

输出:


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


我希望能够在C#中设置此值。除了停止IIS,在XML中设置值然后重新启动之外,是否可以通过编程方式设置该值?

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?

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

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.

参考文献:

  • MD_ETAG_CHANGENUMBER Metabase Property (IIS 6.0)
  • IIS forums thread discussing the problem, with no resolution

推荐答案

我最好的想法很好。这是一个解决方案,它取决于IIS 6.0资源工具包中元数据库资源管理器中的IISMbLib.dll。

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

这篇关于以编程方式从配置数据库IIS6中删除etag后缀(更改号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆