查找新添加的扩展的mime类型
本文关键字:扩展 mime 类型 添加 新添加 查找 | 更新日期: 2023-09-27 18:14:31
如图所示,可以从HKEY_Classes_Root获取"默认" IIS mime类型。但是,当我注册新类型时,我找不到条目-有人知道我如何以程序方式读取所有IIS注册的mime类型吗?
很抱歉回答我自己的问题,但这里张贴的答案(如下所示)解决了IIS 6和;7
NameValueCollection map = new NameValueCollection();
using (DirectoryEntry entry = new DirectoryEntry("IIS://localhost/MimeMap"))
{
PropertyValueCollection properties = entry.Properties["MimeMap"];
Type t = properties[0].GetType();
foreach (object property in properties)
{
BindingFlags f = BindingFlags.GetProperty;
string ext = t.InvokeMember("Extension", f, null, property, null) as String;
string mime = t.InvokeMember("MimeType", f, null, property, null) as String;
map.Add(ext, mime);
}
}
您可能需要在IIS中添加它。
http://technet.microsoft.com/en-us/library/cc725608 (WS.10) . aspx
更新可以试试DirectoryServices API:
public static string GetMimeTypeFromExtension(string extension)
{
using (DirectoryEntry mimeMap =
new DirectoryEntry("IIS://Localhost/MimeMap"))
{
PropertyValueCollection propValues = mimeMap.Properties["MimeMap"];
foreach (object value in propValues)
{
IISOle.IISMimeType mimeType = (IISOle.IISMimeType)value;
if (extension == mimeType.Extension)
{
return mimeType.MimeType;
}
}
return null;
}
}
我可以在。net中设置IIS MIME类型吗?