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:
- He calls
iis://localhost/mimemap
the Metabase Path. Which sounds to me like it is some sort of "path" to a "metabase". - 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
DirectoryEntry(MetabasePath)
returns fine, and it returns an object. The error comes next when you try to access any of the returnedDirectoryEntry
object's properties. They all give a COM "unspecified" error. This happens when the path isn't valid, e.g. "iis://localhost/asdfadsf
" – Colis