添加绑定到IIS而不回收应用程序

时间:2015-06-01 10:19:16

标签: c# iis

我们有一个应用程序允许我们关联多个URL,我们希望允许我们的客户自己添加新的URL,我们有以下代码成功添加绑定:

  using (ServerManager serverManager = new ServerManager())
  {
    var site = serverManager.Sites["SITENAME"];
    var binding = site.Bindings.SingleOrDefault(x => x.Host == hostName);
    if (binding == null)
    {
      binding = site.Bindings.CreateElement("binding");
      binding["protocol"] = "http";
      string ip = "*";
      string port = "80";
      binding["bindingInformation"] = string.Format(@"{0}:{1}:{2}", ip, port, hostName);

      site.Bindings.Add(binding);
      serverManager.CommitChanges();
    }
  }

我们遇到的问题是,这会导致应用程序回收,我已经使用本地IIS在我们的解决方案上对此进行了测试,并且Appliation_Start再次受到攻击。我还手动添加了IIS的绑定,这也导致了回收。虽然我怀疑答案是否定的是他们的解决方案是以编程方式添加绑定而不会导致应用程序回收?

1 个答案:

答案 0 :(得分:2)

您可以尝试更改托管您网站的应用程序池中的设置Disable Recycling for Configuration Changes

在PowerShell中:

Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.applicationHost/applicationPools/add[@name='MyPool']/recycling" -name "disallowRotationOnConfigChange" -value "True"

此处的快速测试表明,添加/删除绑定在更改设置后不再卸载当前的AppDomain。

即使有效,你也想暂时测试一下,以确保它不会破坏其他任何东西。