【发布时间】:2010-09-19 01:41:30
【问题描述】:
我可以通过 ASP.NET 或一些 .NET 代码设置自定义 MIME 类型吗?我需要在 IIS 6 中注册 Silverlight XAML 和 XAP MIME 类型。
【问题讨论】:
标签: .net asp.net silverlight iis-6
我可以通过 ASP.NET 或一些 .NET 代码设置自定义 MIME 类型吗?我需要在 IIS 6 中注册 Silverlight XAML 和 XAP MIME 类型。
【问题讨论】:
标签: .net asp.net silverlight iis-6
添加到主 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]'。
【讨论】:
COM 添加引用选项卡上的“Active DS IIS 命名空间提供程序”。
如果不存在,您必须在您的机器上安装 IIS。
见Is there a way to get ALL the MIME types instead of wrinting a huge case statement?
【讨论】: