用编程方式给IIS里增加MIME类型
来源:互联网 发布:阿里云免费体验 编辑:程序博客网 时间:2024/05/13 02:11
最近在搞一个安装程序,其中有一步,是要给iis增加一个新的mime类型.log,好让用户能下载iis的日志。
iis的所有的操作都可以用System.DirectoryServices里的功能完成。mime类型一定也可以。果然,经过一翻寻找,在msdn中找到。原文如下:http://msdn2.microsoft.com/en-us/library/ms525901.aspx
这里面关键一步是引用Active DS IIS Namespace Provider,这样你就能使用IISOle这个命名空间,和IISMimeType 这个类。
实际代码并不复杂,全部在下面,比较简单,就不多解释。
using System;using System.IO;using System.DirectoryServices;using System.Reflection;using System.Runtime.InteropServices;using System.Collections;namespace System_DirectoryServices_DirectoryEntry_ConfigIIS{ class Program { static void Main(string[] args) { SetMimeTypeProperty("IIS://localhost/W3SVC/1/Root", ".hlp", "application/winhlp"); } static void SetMimeTypeProperty(string metabasePath, string newExtension, string newMimeType) { // metabasePath is of the form "IIS://<servername>/<path>" // for example "IIS://localhost/W3SVC/1/Root" // newExtension is of the form ".<extension>", for example, ".hlp" // newMimeType is of the form "<application>", for example, "application/winhlp" Console.WriteLine("/nAdding {1}->{2} to the MimeMap property at {0}:", metabasePath, newExtension, newMimeType); try { DirectoryEntry path = new DirectoryEntry(metabasePath); PropertyValueCollection propValues = path.Properties["MimeMap"]; Console.WriteLine(" Old value of MimeMap has {0} elements", propValues.Count); object exists = null; foreach (object value in propValues) { // IISOle requires a reference to the Active DS IIS Namespace Provider in Visual Studio .NET IISOle.IISMimeType mimetypeObj = (IISOle.IISMimeType)value; Console.WriteLine(" {0}->{1}", mimetypeObj.Extension, mimetypeObj.MimeType); if (newExtension == mimetypeObj.Extension) exists = value; } if (null != exists) { propValues.Remove(exists); Console.WriteLine(" Found an entry for {0}; removing it before adding the new one.", newExtension); } IISOle.MimeMapClass newObj = new IISOle.MimeMapClass(); newObj.Extension = newExtension; newObj.MimeType = newMimeType; propValues.Add(newObj); path.CommitChanges(); Console.WriteLine(" Done."); } catch (Exception ex) { if ("HRESULT 0x80005006" == ex.Message) Console.WriteLine(" Property MimeMap does not exist at {0}", metabasePath); else Console.WriteLine("Failed in SetMimeTypeProperty with the following exception: /n{0}", ex.Message); } } }}
- 用编程方式给IIS里增加MIME类型
- IIS增加中MIME类型xap,xaml
- [转]使用C++为IIS的虚拟目录增加MIME类型
- windows server 2003 IIS增加中MIME类型
- Win7 在IIS中增加MIME类型文件
- Win7 在IIS中增加MIME类型文件
- IIS中的 MIME类型
- IIS中的 MIME类型
- IIS设置MIME类型
- IIS中的MIME类型
- IIS中的 MIME类型
- IIS中的MIME类型
- IIS中的 MIME类型
- IIS mime类型
- IIS添加mime类型
- iis添加mime类型
- IIS MIME类型支持
- c#为iis增加mime
- IIS的完整控制类
- DotNetBar 6.8.0.1 for VS2003/VS2005
- Google Web Search
- Alan Kay面向对象之父总结的OOP特性
- 彻底弄懂CSS盒子模式(DIV布局快速入门)
- 用编程方式给IIS里增加MIME类型
- 你未必知道的10个CSS技巧 http://blog.csdn.net/nilxin/archive/2005/09/09/476320.aspx
- DXperience 7.2.1 for VS2005
- 无敌杀进程方法
- 好书赏析:《理想专业程序员》
- SAP FI/CO Reading Repository
- 如何在Vista IIS 7 中用 VS2005 调试 Web 项目?
- Hibernate 脏数据检查
- SAP财务知识点