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

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

问题描述

我想从代码隐藏文件中找到 IIS ASP.NET Web 服务器上给定文件扩展名的 MIME 类型.

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 Map 的任何 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 Map 的存储位置.

but that isn't documented as being the same list IIS uses, nor is it documented where the Mime Map is stored.

我可以盲目地调用 FindMimeFromData,但是没有记录为与 IIS 使用的列表相同,我也不能保证 IIS Mime Map 也将从该调用中返回.

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;

    }
}

在 COM 选项卡下添加对 System.DirectoryServices 的引用和对 Active DS IIS Namespace Provider 的引用.扩展名需要有前导点,即 .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 map?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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