IIS:如何获取元数据库路径?

发布于 2024-08-30 00:14:51 字数 2263 浏览 3 评论 0原文

我正在尝试获取 IIS 服务器已知的 MIME 类型列表(您可以看到我在 2 年前提出了这个问题并回答了)。复制粘贴的答案涉及:

GetObject("IIS://LocalHost/MimeMap") msdn

GetObject("IIS://localhost/mimemap") KB246068

GetObject("IIS://localhost/MimeMap") Scott Hanselman 的博客

new DirectoryEntry("IIS://Localhost/MimeMap")) 堆栈溢出

new DirectoryEntry("IIS://Localhost/MimeMap"))< /code> Stack Overflow

新的 DirectoryServices .DirectoryEntry("IIS://localhost/MimeMap") 速度评论


你明白了。每个人都同意您使用了一条神奇的路径iis://localhost/mimemap。这非常有效,除了有时不起作用的时候。

我能找到的关于失败原因的唯一线索 来自IIS MVP,Chris Crowe 的博客

string ServerName = "LocalHost";
string MetabasePath = "IIS://" + ServerName + "/MimeMap";
    // Note: This could also be something like
    // string MetabasePath = "IIS://" + ServerName + "/w3svc/1/root";

DirectoryEntry MimeMap = new DirectoryEntry(MetabasePath);

这里有两条线索:

  1. 他将 iis://localhost/mimemap 称为元数据库路径。在我看来,这是某种“元数据库”的“路径”。
  2. 他说,到元数据库路径可能是其他东西;他举了一个例子来说明它可能是什么样子。

现在,我和整个地球都在将“MetabasePath”硬编码为

iis://localhost/MimeMap

它到底应该是什么?代码应该做什么来构造有效的 MetabasePath?


注意:我没有收到访问被拒绝错误,当您有无效的 MetabasePath 时,错误是相同的,例如 iis://localhost/SoTiredOfThis

i'm trying to get the list of mime types known to an IIS server (which you can see was asked and and answered by me 2 years ago). The copy-pasted answer involves:

GetObject("IIS://LocalHost/MimeMap") msdn

GetObject("IIS://localhost/mimemap") KB246068

GetObject("IIS://localhost/MimeMap") Scott Hanselman's Blog

new DirectoryEntry("IIS://Localhost/MimeMap")) Stack Overflow

new DirectoryEntry("IIS://Localhost/MimeMap")) Stack Overflow

New DirectoryServices.DirectoryEntry("IIS://localhost/MimeMap") Velocity Reviews


You get the idea. Everyone agrees that you use a magical path iis://localhost/mimemap. And this works great, except for the times when it doesn't.

The only clue i can find as to why it fails, is from an IIS MVP, Chris Crowe's, blog:

string ServerName = "LocalHost";
string MetabasePath = "IIS://" + ServerName + "/MimeMap";
    // Note: This could also be something like
    // string MetabasePath = "IIS://" + ServerName + "/w3svc/1/root";

DirectoryEntry MimeMap = new DirectoryEntry(MetabasePath);

There are two clues here:

  1. He calls iis://localhost/mimemap the Metabase Path. Which sounds to me like it is some sort of "path" to a "metabase".
  2. He says that the path to the metabase could be something else; and he gives an example of what it could be like.

Right now i, and the entire planet, are hardcoding the "MetabasePath" as

iis://localhost/MimeMap

What should it really be? What should the code be doing to construct a valid MetabasePath?


Note: i'm not getting an access denied error, the error is the same when you have an invalid MetabasePath, e.g. iis://localhost/SoTiredOfThis

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

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

发布评论

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

评论(2

彩扇题诗 2024-09-06 00:14:51

如果您正在使用本地计算机的 IIS 配置,即您的代码和 IIS 位于同一台机器上,那么指定以下内容就足够了:

IIS://Localhost/mimemap

IIS:< /code> 部分在 OLE 术语中也称为绰号。

如果您打开 IIS6 元数据库文件 (C:\Windows\System32\inetsrv\metabase.xml),您会发现一个大的 XML“斑点”。这实际上是一个扁平化的树结构。

配置数据库中的路径由 Location 属性表示。

名称 IIS://localhost 映射到 Location 路径 /LM,它实际上是树根。

名称 IIS://localhost/MimeMap 映射到 Location 路径 /LM/MimeMap

如果您的代码正在访问远程计算机上的元数据库,则无需指定 IIS://localhost/[path],而是指定 IIS://[RemoteMachineName]/[path]代码>.这就是克里斯·克劳斯评论的意思。

IIS://localhost/MimeMap 也是主 Mime 类型列表。所有站点都继承此列表(IIS 配置数据库严重依赖于继承的属性)。

如果您想覆盖特定站点的 Mime 类型,那么您需要修改:

IIS://localhost/W3SVC/[iisnumber]/ROOT/MimeMap

打开 IIS 元数据库文件并深入了解一下,了解引擎盖下到底发生了什么。

更新:

要回答有关为什么可以在路径无效的情况下创建 DirectoryEntry 对象的问题,DirectoryEntry 是一个通用包装对象,用于绑定不同类型的 ADSI 提供程序,例如 IIS、LDAP 和 WinNT。它允许创建 DirectoryEntry 对象,其中指定的路径不一定有匹配的对象。某些 ADSI 提供程序操作可能需要此功能。

DirectoryEntry 上有一个静态方法,名为 Exists 可用于测试对象是否存在。例如:

// Does Default Website exist?
if(DirectoryEntry.Exists("IIS://localhost/w3svc/1"))
{
  // Do work...
}

If you're working with the IIS config of your local machine i.e. your code and IIS are on the same box then it's sufficient to specify:

IIS://Localhost/mimemap

The IIS: portion is also known as a moniker in OLE parlance.

If you open the IIS6 metabase file (C:\Windows\System32\inetsrv\metabase.xml) you'll find a large 'blob' of XML. This is in fact a flattened out tree structure.

Paths in the metabase are represented by Location attributes.

The moniker IIS://localhost maps to the Location path /LM which is effectively the tree root.

The moniker IIS://localhost/MimeMap maps to the Location path /LM/MimeMap.

If your code is accessing the metabase on remote machines then instead of specifiying IIS://localhost/[path], one would specify IIS://[RemoteMachineName]/[path]. This is what Chris Crowes comment means.

IIS://localhost/MimeMap is also the master Mime Type list. All sites inherit this list (the IIS Metabase relies heavily on inherited properties).

If you wanted to override the Mime types for a specific site then you'd modify:

IIS://localhost/W3SVC/[iisnumber]/ROOT/MimeMap

It's useful to open up the IIS metabase file and have a dig around to understand what's going on under the bonnet.

Update:

To answer your question about why you can create a DirectoryEntry object where the path is invalid, DirectoryEntry is a general purpose wrapper object used to bind against different types of ADSI providers such as IIS, LDAP and WinNT. It permits creation of DirectoryEntry objects where there may not necessarily be a matching object at the path specified. Some ADSI provider operations may require this capability.

There is a static method on DirectoryEntry called Exists that you can use to test for the existence of objects. For example:

// Does Default Website exist?
if(DirectoryEntry.Exists("IIS://localhost/w3svc/1"))
{
  // Do work...
}
生活了然无味 2024-09-06 00:14:51

我在尝试执行此操作时遇到返回 0x80005000 的问题。我的问题的愚蠢原因是我使用的是 IIS7 并且没有安装 IIS6 元数据库兼容性支持。

I was having a problem with getting 0x80005000 returned when trying to do this. The stupid cause of my problem was that I was using IIS7 and hadn't installed IIS6 metabase compatibility support.

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