IIS:如何获取Metabase路径? [英] IIS: How to get the Metabase path?

查看:202
本文介绍了IIS:如何获取Metabase路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取IIS服务器已知的mime类型列表(你可以看到2年前我被问及并回答了)。复制粘贴的答案包括:

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的博客

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

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

新的DirectoryServices.Directory条目(IIS:// localhost / MimeMap) Velocity评论

你明白了。每个人都同意你使用一个神奇的路径 iis:// localhost / mimemap 。这种方法效果很好,除非时间不好。

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.

唯一的线索我可以找到它失败的原因,来自IIS MVP,Chris Crowe,博客

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

这里有两条线索:


  1. 他调用 iis:// localhost / mimemap 元数据库路径。这对我来说听起来像是某种路径配置数据库

  2. 他说路径元数据库可能是其他的东西;他给出了一个例子。

  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.

现在我和整个星球正在硬编码 MetabasePath as

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

iis://localhost/MimeMap

它应该是什么?代码应该如何构建有效的MetabasePath?

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

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

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

推荐答案

如果你正在工作使用本地计算机的IIS配置,即您的代码和IIS位于同一个框中,则只需指定:

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

IIS:部分在OLE用语中也称为名字对象。

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

如果打开IIS6配置数据库文件( C:\Windows\System32 \inetsrv\metabase.xml )你会发现一大堆blob的XML。这实际上是一个扁平的树结构。

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.

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

Paths in the metabase are represented by Location attributes.

名字对象 IIS:// localhost 映射到位置路径 / LM 实际上是树根。

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

名字对象 IIS:// localhost / MimeMap 映射到位置路径 / LM / MimeMap

如果您的代码正在访问远程计算机上的元数据库,那么不会指定 IIS:// localhost / [path] ,指定 IIS:// [RemoteMachineName] / [path] 。这就是Chris Crowes评论的含义。

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 也是主Mime类型列表。所有站点都继承此列表(IIS Metabase严重依赖于继承的属性)。

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

如果要覆盖特定站点的Mime类型,则需要修改:

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

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

打开IIS元数据库文件并深入了解发动机罩下的情况是很有用的。

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

更新:

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

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.

DirectoryEntry 上有一个名为 存在 ,您可以使用它来测试物体的存在。例如:

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...
}

这篇关于IIS:如何获取Metabase路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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