gpt4 book ai didi

iis-7.5 - IIS 7.5 applicationHost.config 文件未更新

转载 作者:行者123 更新时间:2023-12-03 10:02:48 25 4
gpt4 key购买 nike

我目前正在使用 Microsoft.Web.Administration (MWA) 命名空间,以便调整我们的应用程序以使用新 API 配置 IIS 7.5。
我知道所有 IIS 级别的更改都应在以下文件中表示(我使用的是 Win2K8-R2):

%WINDIR%\System32\inetsrv\config\applicationHost.config

So, when I use the ServerManager object to commit the configuration changes the file should be updated accordingly.

After adding a new MIME type (programmatic with MWA) I did not see any changes in the applicationHost.config file, but I do see the new MIME type in the IIS manager window and IIS recognizes this MIME type without problems. Even after restating the OS - The config file does not contain the newly added MIME type, but the IIS manager window does list it.

Because my application pools are forced to 32-bit (Enable32BitAppOnWin64 = true), I thought that the related config file should be located under %WINDIR%\SysWOW64\inetsrv\Config, but (if it exists...) - it also does not change after the code commits the updates.

Can someone please explain this? Am I missing something (looking at the wrong file maybe?)? Can someone please shed some light on the SysWOW64\inetsrv\config directory?

This is my code for adding the MIME type:

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

最佳答案

我刚刚试过你的代码,它工作正常。您是否知道此 mime 类型正在添加到全局 mime 类型集合中,而不是添加到站点中?

它还被添加到 <staticContent> 的末尾列表,当您这样做时,此列表不会重新排序 ServerManager.CommitChanges() .

同样在 Windows 2008-R2 上 applicationHost.config 的正确位置是在:

C:\Windows\System32\inetsrv\config

我猜您是使用 notepad.exe 或 NotePad2 打开此文件(32 位编辑器无法打开它)。 Notepad 不会在更改时重新加载文件,并且需要告诉 NotePad2 显示文件更改通知 (alt-F5),开箱即用。

也可以尝试添加一些不寻常的东西,比如 .xxx ,运行您的更新,然后打开配置文件并进行搜索。我保证它会在那里。

更新:

除了您在下面的评论之外,我不确定您如何打开 applicationHost.config使用 NotePad++ 或任何 32 位编辑器,我当然不能。您可以下载 64 位编辑器 NotePad2:

http://www.flos-freeware.ch/notepad2.html



候选版本工作正常。

在任何 64 位 Windows 2008 或 Windows 7 的默认安装中不应该有 applicationHost.configC:\Windows\SysWOW64\inetsrv\Config文件夹。我不知道你为什么会在那里看到一个。

关于iis-7.5 - IIS 7.5 applicationHost.config 文件未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5696801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com