在程序安装时添加IIS6对.jse文件的解析
2003 上的IIS6如果不配置的话,是不会对.jse的文件进行解析的.我们在发现此问题的时候,一般建议客户手工在IIS中添加对此MIME类型的解析.前段时间,我准备将这个操作写入FAQ的时候,有人问我,能不能在安装包安装的时候解决这个问题,以免在安装文档中写上这段废话?
答案当然是肯定的.
步骤如下:
在你的自定义操作安装类中添加以下代码:
上述代码改动成方法,在其他地方调用也是可以的. 不过IIS6上就需要设一次就可以了.
注意:需要添加对IISOle.dll 和ActiveDs.dll的引用,他们是activex控件.
答案当然是肯定的.
步骤如下:
在你的自定义操作安装类中添加以下代码:
string newExtension = ".jse";
string newMimeType = "application/x-javascript";
DirectoryEntry dir1 = new DirectoryEntry("IIS://LocalHost/mimemap");
PropertyValueCollection propValues = dir1.Properties["MimeMap"];
object exists = null;
foreach (object values in propValues)
{
IISOle.IISMimeType mimetypeObj = (IISOle.IISMimeType)values;
if (newExtension == mimetypeObj.Extension)
{
exists = values;
}
}
if (null != exists)
{
propValues.Remove(exists);
}
IISOle.MimeMapClass newObj = new IISOle.MimeMapClass();
newObj.Extension = newExtension;
newObj.MimeType = newMimeType;
propValues.Add(newObj);
dir1.CommitChanges();
string newMimeType = "application/x-javascript";
DirectoryEntry dir1 = new DirectoryEntry("IIS://LocalHost/mimemap");
PropertyValueCollection propValues = dir1.Properties["MimeMap"];
object exists = null;
foreach (object values in propValues)
{
IISOle.IISMimeType mimetypeObj = (IISOle.IISMimeType)values;
if (newExtension == mimetypeObj.Extension)
{
exists = values;
}
}
if (null != exists)
{
propValues.Remove(exists);
}
IISOle.MimeMapClass newObj = new IISOle.MimeMapClass();
newObj.Extension = newExtension;
newObj.MimeType = newMimeType;
propValues.Add(newObj);
dir1.CommitChanges();
注意:需要添加对IISOle.dll 和ActiveDs.dll的引用,他们是activex控件.
浙公网安备 33010602011771号