【发布时间】:2011-08-07 11:54:53
【问题描述】:
我目前正在使用 Microsoft.Web.Administration (MWA) 命名空间,以便调整我们的应用程序以使用新 API 配置 IIS 7.5。 我知道所有 IIS 级别的更改都应该在以下文件中表示(我在 Win2K8-R2 上):
%WINDIR%\System32\inetsrv\config\applicationHost.config
所以,当我使用ServerManager 对象提交配置更改时,文件应该相应地更新。
添加新的 MIME 类型(使用 MWA 进行编程)后,我在 applicationHost.config file 中没有看到任何更改,但我确实在 IIS 管理器窗口中看到了新的 MIME 类型,并且 IIS 可以毫无问题地识别此 MIME 类型。即使在重新启动操作系统后 - 配置文件不包含新添加的 MIME 类型,但 IIS 管理器窗口确实列出了它。
因为我的应用程序池被强制为 32 位(Enable32BitAppOnWin64 = true),我认为相关的配置文件应该位于%WINDIR%\SysWOW64\inetsrv\Config 下,但是(如果它存在...) - 之后它也不会改变代码提交更新。
有人可以解释一下吗?我是否遗漏了什么(可能是查看了错误的文件?)?有人可以解释一下SysWOW64\inetsrv\config 目录吗?
这是我添加 MIME 类型的代码:
ServerManager manager = new ServerManager();
ConfigurationElementCollection staticContentCollection = manager
.GetApplicationHostConfiguration()
.GetSection("system.webServer/staticContent")
.GetCollection();
//MIMETypes is a string[] array, each object is {FileExt},{MIMETypeStr}
foreach (string pair in MIMETypes)
{
string[] mimeProps = pair.Split(',');
ConfigurationElement mimeTypeEl = staticContentCollection
.Where(a =>
(string)a.Attributes["fileExtension"].Value == mimeProps[0])
.FirstOrDefault();
if (mimeTypeEl != null)
{
staticContentCollection.Remove(mimeTypeEl);
}
ConfigurationElement mimeMapElement =
staticContentCollection.CreateElement("mimeMap");
mimeMapElement["fileExtension"] = mimeProps[0];
mimeMapElement["mimeType"] = mimeProps[1];
staticContentCollection.Add(mimeMapElement);
}
manager.CommitChanges();
//At this point all is working but the config file does not reflect the change
【问题讨论】:
标签: iis-7.5 mime-types applicationhost