【问题标题】:iis Creating new application and enabling Windows Authentication Failsiis 创建新应用程序并启用 Windows 身份验证失败
【发布时间】:2014-06-16 19:27:29
【问题描述】:

我可以成功创建一个应用程序池和一个应用程序并将它们链接在一起。

然而,我没有做的是将应用程序 Windows 身份验证设置为 true,将匿名身份验证设置为 false。

我将一大堆示例拼凑成一个来完成这项工作,但我不断收到以下错误。

此配置部分不能用于此路径。有时候是这样的 当该部分锁定在父级别时。锁定是通过 默认(overrideModeDefault="Deny"),或由位置显式设置 带有 overrideMode="Deny" 或旧的 allowOverride="false" 的标记。

现在除非 overrideMode 显然需要等于 Allow。我该如何做到这一点?

  public static bool CreateApplication(String websiteName, String applicationName, String appDIR,String appPoolName)
  {
     try
      {
      ServerManager iisManager = new ServerManager();

      if (!applicationName.Contains("/"))
          applicationName = "/" + applicationName;



      var app = iisManager.Sites[websiteName].Applications.Add(applicationName, appDIR);                             


      app.ApplicationPoolName = appPoolName;

      var config = app.GetWebConfiguration();

      var anonsection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", iisManager.Sites[websiteName].Name + applicationName);

      //This is where it fails 
      anonsection["enabled"] = false;

      var winsection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", iisManager.Sites[websiteName].Name + applicationName);
      winsection["enabled"] = true;

      iisManager.CommitChanges();
      return true;
    }
    catch
    {
      return false;
    }
 }

【问题讨论】:

    标签: c# iis


    【解决方案1】:

    在管理员命令提示符下使用以下命令

    %windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/security/authentication/windowsAuthentication
    %windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/security/authentication/anonymousAuthentication
    

    这将解锁那些配置部分。

    【讨论】:

    • 这需要在每台运行此代码的机器上完成吗?
    • 是的。但是您可能可以使用Process.Start 将其作为代码的一部分运行。我没试过。
    • 好吧,我得试一试。我正在尝试构建安装程序。
    • 使用 Process.Start(path,arguments) 我得到了这个工作。谢谢
    猜你喜欢
    • 2017-02-11
    • 2012-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-11
    • 2011-05-07
    • 1970-01-01
    相关资源
    最近更新 更多