我可以在 .NET 中设置 IIS MIME 类型吗? [英] Can I setup an IIS MIME type in .NET?
问题描述
我可以通过 ASP.NET 或某些 .NET 代码设置自定义 MIME 类型吗?我需要在 IIS 6 中注册 Silverlight XAML 和 XAP MIME 类型.
Can I setup a custom MIME type through ASP.NET or some .NET code? I need to register the Silverlight XAML and XAP MIME types in IIS 6.
推荐答案
添加到主 MIME 类型列表:
To add to the master mime type list:
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 Namespace Provider".
'System.DirectoryServices' on the .NET add references tab
'Active DS IIS Namespace Provider' on the COM add references tab.
要为特定站点配置 mime 类型,请更改 ..
To configure a mime type for a specific site, change ..
'IIS://Localhost/MimeMap'
到
'IIS://Localhost/W3SVC/[iisnumber]/root'
...用网站的 IISNumber 替换 '[iisnumber]'
.
...replacing '[iisnumber]'
with the IISNumber of the website.
这篇关于我可以在 .NET 中设置 IIS MIME 类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!