ASP.NET/IIS6:如何搜索服务器的MIME映射? [英] ASP.NET/IIS6: How to search the server's mime map?

查看:117
本文介绍了ASP.NET/IIS6:如何搜索服务器的MIME映射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到的MIME类型从code-隐藏文件的IIS ASP.NET web服务器上的特定文件扩展名。

i want to find the mime-type for a given file extension on an IIS ASP.NET web-server from the code-behind file.

我要搜索提供了一个文件时,服务器本身使用相同的列表。这意味着任何MIME类型的Web服务器管理员已添加到MIME映射的将被列入的

i want to search the same list that the server itself uses when serving up a file. This means that any mime types a web-server administrator has added to the Mime Map will be included.

我可以盲目使用

HKEY_CLASSES_ROOT\MIME\Database\Content Type

但没有记录为相同的列表IIS使用,也不是记录,其中的 MIME映射的存储。

我可以叫盲目 FindMimeFromData ,但不记录为同一列表IIS使用,我也不能保证IIS的 MIME映射的也将被从该调用返回。

i could blindly call FindMimeFromData, but that isn't documented as being the same list IIS uses, nor can i guarantee that the IIS Mime Map will also be returned from that call.

推荐答案

这里有一个我做了早些时候:

Here's one I made earlier:

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;

    }
}

添加引用的System.DirectoryServices 和COM选项卡下的活动DS IIS命名空间提供商的参考。扩展需要有前导点,即。FLV

Add a reference to System.DirectoryServices and a reference to Active DS IIS Namespace Provider under the COM tab. The extension needs to have the leading dot, i.e. .flv.

这篇关于ASP.NET/IIS6:如何搜索服务器的MIME映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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