Omr*_*ela 28 applicationhost iis-7.5 mime-types
我目前正在使用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
Run Code Online (Sandbox Code Playgroud)
Kev*_*Kev 25
我只是尝试了你的代码,它工作正常.您知道这个mime类型被添加到全局mime类型集合而不是添加到站点吗?
它也会被添加到<staticContent>
列表的末尾,当你这样做时,这个列表不会被重新排序ServerManager.CommitChanges()
.
同样在Windows 2008-R2上,正确的位置applicationHost.config
是:
C:\Windows\System32\inetsrv\config
我猜你要么使用notepad.exe或NotePad2来打开这个文件(32位编辑器无法打开它).记事本不会在更改时重新加载文件,需要告诉NotePad2显示文件更改通知(alt-F5),开箱即用它不会.
还尝试添加一些不寻常的东西.xxx
,运行您的更新,然后打开配置文件并进行搜索.我保证它会在那里.
更新:
除了下面的评论之外,我不确定你是如何applicationHost.config
使用NotePad ++或任何32位编辑器打开的,我当然不能.你能下载NotePad2这是一个64位编辑器:
发布候选人工作得很好.
在任何64位Windows 2008或Windows 7的默认安装上applicationHost.config
,该C:\Windows\SysWOW64\inetsrv\Config
文件夹中不应该有.我不确定你为什么会在那里看到一个.
归档时间: |
|
查看次数: |
34459 次 |
最近记录: |