【问题标题】:IIS reverses web site settings when stoppingIIS 在停止时反转网站设置
【发布时间】:2012-03-21 15:48:32
【问题描述】:

我在配置 IIS 时遇到问题。我以编程方式在网站下创建一个网站和一个应用程序(虚拟目录)。在其他设置中,我在应用程序设置中添加了通配符应用程序映射。当 IIS 重新启动时,它会删除通配符应用程序映射(以及一些其他设置,但为了简单起见,我只提到通配符映射)。我可以使用 IIS 管理器重新添加地图,但是当我重新启动 IIS 时,地图会被删除。但是 - 如果我添加通配符映射,然后在不重新启动 IIS 的情况下,首先使用浏览器点击该应用程序中的页面,那么任何后续 IIS 重新启动都不会导致映射消失。知道发生了什么吗?

这是我的代码:

// root virtual dir object
string strRootVirtDirPath = "IIS://localhost/w3svc/" + strWebSiteID + "/root";
DirectoryEntry deRootVirtDir = new DirectoryEntry(strRootVirtDirPath);

// add new virtual dir
DirectoryEntry deNewVirtDir = deRootVirtDir.Children.Add(strAppName, "IIsWebVirtualDir");

deNewVirtDir.Properties["Path"].Value = strPhysicalDir;
deNewVirtDir.Properties["AppFriendlyName"].Value = strAppName;
deNewVirtDir.Properties["AppRoot"].Value = "/LM/W3SVC/" + strWebSiteID + "/Root/" + strAppName;
deNewVirtDir.Properties["AppPoolId"].Value = strAppPoolName;

// create the application
deNewVirtDir.Invoke("AppCreate", 1);

// commit changes
deNewVirtDir.CommitChanges();
deRootVirtDir.CommitChanges();
deNewVirtDir.Close();
deRootVirtDir.Close();

【问题讨论】:

  • 对不起,忘了说是 IIS 6
  • 您在创建虚拟目录时是否正确调用了 .Invoke("AppCreate"),然后在更新设置后调用了 .CommitChanges()?
  • 不确定如何验证函数调用是否正确。代码执行成功,我没有得到任何异常。这是我的代码:
  • // 创建根虚拟目录对象字符串 strRootVirtDirPath = "IIS://localhost/w3svc/" + strWebSiteIDLocal + "/root"; DirectoryEntry deRootVirtDir = new DirectoryEntry(strRootVirtDirPath); // 添加新的虚拟目录 DirectoryEntry deNewVirtDir = deRootVirtDir.Children.Add(strApplicationNameLocal, "IIsWebVirtualDir"); // 设置物理目录 deNewVirtDir.Properties["Path"].Value = strRootDir;
  • // 设置应用相关的属性 deNewVirtDir.Properties["AppFriendlyName"].Value = strApplicationNameLocal; // 应用程序友好名称 deNewVirtDir.Properties["AppRoot"].Value = "/LM/W3SVC/" + strWebSiteIDLocal + "/Root/" + strApplicationNameLocal; deNewVirtDir.Properties["AppPoolId"].Value = strAppPoolNameLocal; // 要使用的应用程序池 // 保存到目前为止的所有更改,以防“AppCreate”失败 deNewVirtDir.CommitChanges(); deRootVirtDir.CommitChanges();

标签: iis application-settings


【解决方案1】:

找出问题所在。在 Microsoft 的知识库文章 286196 中有描述:http://support.microsoft.com/kb/286196 我所有受影响的机器都是 Windows Server 2K3 R2,就像文章中描述的那样。

【讨论】:

    猜你喜欢
    • 2018-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-27
    • 1970-01-01
    • 1970-01-01
    • 2017-01-13
    • 1970-01-01
    相关资源
    最近更新 更多