您的位置:首页 > 编程语言

用编程方式给IIS增加MIME类型

2008-02-12 16:55 495 查看
前段时间,在完成FLV视频播放,遭遇一个“在服务器上无法播放FLV视频”问题。奇怪的是在我本机上试验是可以的,当放到服务器上就不行。(程序运行环境:windows 2003 +IIs 6.0)

刚开始以为可能是FLV视频文件太大,导致IIS不能下载FLV视频,不能播放。于是修改了IIS附件下载限制,可是到最终在服务器上还是不能播放FLV视频。后来在网络上看到IIS是不支持播放Flash视频,这下可槽糕了,但怎么想也想不通啊,很多视频网站基本上都采用FLASH播放,他们是怎么做到的呢。通过网上资料,最终寻找到ADOBD公司给出“Windows 2003 Server does not stream FLV videos”解决方案:(原文如下:http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_19439&sliceId=1

Please be aware that these steps do not resolve any issue with Flash, but are a configuration step for Microsoft Windows 2003 and Microsoft IIS Server 6.0. Any difficulties in executing these instructions or any errors that may arise from modifying your system settings should be addressed to Microsoft. For more details, please refer to your IIS documentation.

On the Windows 2003 server, open the Internet Information Services Manager.

Expand the Local Computer Server.

Right-click the local computer server and select Properties.

Select the MIME Types tab.

Click New and enter the following information:

Associated Extension box: .FLV

MIME Type box:flv-application/octet-stream

Click OK.

Restart the World Wide Web Publishing service.

设置好后,播放器果然可以播放了。到目前为止,可能有人会问,好像跟该文章主题“用编程方式给IIS增加MIME类型”,没有多大关系吧。好,现在就开始进入正题,既然可以手动设置IIS的MIME类型,那能不能通过程序方式自动给IIS添加MIME类型。那答案是肯定的。只要能获取到IIS控制台的MIME属性就OK了。

IIS的所有操作都可以由System.DirectoryServices来完成。同样地,MIME也应该是可以的,在MSDN中找到一篇关于“Setting MIME Type Properties Using System.DirectoryServices”文章,原文如下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 SettingMIMEType


以上代码在WINDWOS2003 + Visual Studio 2008 + IIS 6.0环境中,测试通过。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: