Can I setup an IIS MIME type in .NET?

匿名 (未验证) 提交于 2019-12-03 01:14:02

问题:

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.

回答1:

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(); } 

Add a reference to :

'System.DirectoryServices' on the .NET add references tab
'Active DS IIS Namespace Provider' on the COM add references tab.

To configure a mime type for a specific site, change ..

'IIS://Localhost/MimeMap'

to

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

...replacing '[iisnumber]' with the IISNumber of the website.



回答2:

'Active DS IIS Namespace Provider' on the COM add references tab.

If it's not there, you have to install IIS on your machine.

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!