【问题标题】:Can I setup an IIS MIME type in .NET?我可以在 .NET 中设置 IIS MIME 类型吗?
【发布时间】:2010-09-19 01:41:30
【问题描述】:

我可以通过 ASP.NET 或一些 .NET 代码设置自定义 MIME 类型吗?我需要在 IIS 6 中注册 Silverlight XAML 和 XAP MIME 类型。

【问题讨论】:

    标签: .net asp.net silverlight iis-6


    【解决方案1】:

    添加到主 MIME 类型列表:

    using (DirectoryEntry mimeMap = new DirectoryEntry("IIS://Localhost/MimeMap"))
    {
        PropertyValueCollection propValues = mimeMap.Properties["MimeMap"];
    
        IISOle.MimeMapClass newMimeType = new IISOle.MimeMapClass();
        newMimeType.Extension = extension; // string - .xap
        newMimeType.MimeType = mimeType;   // string - application/x-silverlight-app
    
        propValues.Add(newMimeType);
        mimeMap.CommitChanges();
    }
    

    添加对 :

    的引用

    .NET 添加引用选项卡上的“System.DirectoryServices”
    COM 添加引用选项卡上的“Active DS IIS 命名空间提供程序”。

    要为特定站点配置 MIME 类型,请更改 ..

    'IIS://Localhost/MimeMap'

    'IIS://Localhost/W3SVC/[iisnumber]/root'

    ...用网站的 IISNumber 替换 '[iisnumber]'

    【讨论】:

      【解决方案2】:

      COM 添加引用选项卡上的“Active DS IIS 命名空间提供程序”。

      如果不存在,您必须在您的机器上安装 IIS。

      Is there a way to get ALL the MIME types instead of wrinting a huge case statement?

      【讨论】:

        猜你喜欢
        • 2011-12-04
        • 2012-07-09
        • 2010-09-15
        • 2021-09-13
        • 2013-04-03
        • 1970-01-01
        • 2014-05-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多