使用安装程序以编程方式在 IIS 中创建应用程序池时出错
Error creating an Application Pool in IIS programmatically with an installer
我已经使用 Visual Studio 2017 版本 15.7.1 创建了一个安装项目。
我有这个 post 安装自定义操作:
[RunInstaller(true)]
public partial class PostInstallActions : Installer
{
private const string siteName = "Default Web Site";
private const string appPoolName = "TRZF AppPool";
private const string webAppPath = "/TRZF";
private const string windowsAuthenticationPath =
"system.webServer/security/authentication/windowsAuthentication";
public PostInstallActions()
{
InitializeComponent();
}
public override void Install(IDictionary state)
{
base.Install(state);
// Do my custom install actions
}
public override void Commit(IDictionary state)
{
base.Commit(state);
// Do my custom commit actions
ServerManager serverManager = new ServerManager();
ApplicationPool trzfAppPool =
serverManager.ApplicationPools.Add(appPoolName);
trzfAppPool.Enable32BitAppOnWin64 = true;
trzfAppPool.ManagedRuntimeVersion = "v4.0";
trzfAppPool.ProcessModel.IdentityType =
ProcessModelIdentityType.ApplicationPoolIdentity;
Application trzfApp = serverManager.Sites[siteName].Applications[webAppPath];
trzfApp.ApplicationPoolName = appPoolName;
Configuration config = trzfApp.GetWebConfiguration();
ConfigurationSection windowsAuthenticationSection =
config.GetSection(windowsAuthenticationPath);
windowsAuthenticationSection["enabled"] = true;
serverManager.CommitChanges();
}
}
运行 Windows 10 Enterprise 2016 LTSB,版本 1607 上的安装程序出现错误。
错误发生在提交阶段:
Error 1001. Error 1001. An exception occurred during the Commit phase
of the installation. This exception will be ignored and installation
will continue. However, the application might not function correctly
after installation is complete. --> This configuration section cannot
be used at this path. This happens when the section is locked at a
parent level. Locking is either by default
(overrideModeDefault="Deny"), or set explicitly by a location tag with
overrideMode="Deny" or the legacy allowOverride="false".
我有 运行 它的管理权限,但我得到同样的错误。
我该如何解决这个错误?
Windows 认证部分默认是锁定的,所以你不能在 web.config
中设置它(你在上面的代码中尝试过的)。尝试在applicationHost.config
中设置为location
标签,如下
// server config "Website1"
var config = server.GetApplicationHostConfiguration();
// enable Windows authentication
var windowsSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", "WebSite1");
Assert.Equal(OverrideMode.Inherit, windowsSection.OverrideMode);
Assert.Equal(OverrideMode.Deny, windowsSection.OverrideModeEffective);
Assert.False(windowsSection.IsLocked);
Assert.True(windowsSection.IsLocallyStored);
var windowsEnabled = (bool)windowsSection["enabled"];
Assert.True(windowsEnabled);
windowsSection["enabled"] = false;
Assert.Equal(false, windowsSection["enabled"]);
我已经使用 Visual Studio 2017 版本 15.7.1 创建了一个安装项目。
我有这个 post 安装自定义操作:
[RunInstaller(true)]
public partial class PostInstallActions : Installer
{
private const string siteName = "Default Web Site";
private const string appPoolName = "TRZF AppPool";
private const string webAppPath = "/TRZF";
private const string windowsAuthenticationPath =
"system.webServer/security/authentication/windowsAuthentication";
public PostInstallActions()
{
InitializeComponent();
}
public override void Install(IDictionary state)
{
base.Install(state);
// Do my custom install actions
}
public override void Commit(IDictionary state)
{
base.Commit(state);
// Do my custom commit actions
ServerManager serverManager = new ServerManager();
ApplicationPool trzfAppPool =
serverManager.ApplicationPools.Add(appPoolName);
trzfAppPool.Enable32BitAppOnWin64 = true;
trzfAppPool.ManagedRuntimeVersion = "v4.0";
trzfAppPool.ProcessModel.IdentityType =
ProcessModelIdentityType.ApplicationPoolIdentity;
Application trzfApp = serverManager.Sites[siteName].Applications[webAppPath];
trzfApp.ApplicationPoolName = appPoolName;
Configuration config = trzfApp.GetWebConfiguration();
ConfigurationSection windowsAuthenticationSection =
config.GetSection(windowsAuthenticationPath);
windowsAuthenticationSection["enabled"] = true;
serverManager.CommitChanges();
}
}
运行 Windows 10 Enterprise 2016 LTSB,版本 1607 上的安装程序出现错误。
错误发生在提交阶段:
Error 1001. Error 1001. An exception occurred during the Commit phase of the installation. This exception will be ignored and installation will continue. However, the application might not function correctly after installation is complete. --> This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
我有 运行 它的管理权限,但我得到同样的错误。
我该如何解决这个错误?
Windows 认证部分默认是锁定的,所以你不能在 web.config
中设置它(你在上面的代码中尝试过的)。尝试在applicationHost.config
中设置为location
标签,如下
// server config "Website1"
var config = server.GetApplicationHostConfiguration();
// enable Windows authentication
var windowsSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", "WebSite1");
Assert.Equal(OverrideMode.Inherit, windowsSection.OverrideMode);
Assert.Equal(OverrideMode.Deny, windowsSection.OverrideModeEffective);
Assert.False(windowsSection.IsLocked);
Assert.True(windowsSection.IsLocallyStored);
var windowsEnabled = (bool)windowsSection["enabled"];
Assert.True(windowsEnabled);
windowsSection["enabled"] = false;
Assert.Equal(false, windowsSection["enabled"]);