【问题标题】:Setting up ASP settings using Microsoft.Web.Administration使用 Microsoft.Web.Administration 设置 ASP 设置
【发布时间】:2017-06-15 11:47:45
【问题描述】:

是否可以使用Microsoft.Web.Administration 包为给定的location 配置asp 设置?

我想以编程方式将以下部分添加到本地 IIS applicationHost.config 文件中。

<configuration>
    ...

    <location path="Default Web Site/myAppPath">
        <system.webServer>
            <asp appAllowClientDebug="true" appAllowDebugging="true" enableParentPaths="true" scriptErrorSentToBrowser="true" />
        </system.webServer>
    </location>

</configuration>

我找不到任何方法,因为此部分不属于任何可以使用此软件包维护的站点或应用程序。

如果没有,有没有更多功能丰富的替代 Microsoft.Web.Administration

【问题讨论】:

    标签: c# iis asp-classic


    【解决方案1】:

    这是可能的。如果您的服务器上安装了Administration Pack,甚至还有一个向导可以帮助您从 IIS 管理器 GUI 创建此类脚本。

    IIS 管理器 > 站点 > 默认网站 > myAppPath > 配置编辑器

    为默认网站拍摄了屏幕截图,但对于像您这样的虚拟应用程序,步骤相同。

    选择部分 (system.webServer/asp) 和配置文件 (ApplicationHost.config &lt;location path="Default Web Site/myAppPath"&gt;) 并进行更改。

    进行更改后不要点击应用,只需点击生成脚本。这将打开一个对话框,其中包含一些可用于以编程方式进行更改的脚本。

    using System;
    using System.Text;
    using Microsoft.Web.Administration;
    
    internal static class Sample {
    
        private static void Main() {
    
            using(ServerManager serverManager = new ServerManager()) { 
                Configuration config = serverManager.GetApplicationHostConfiguration();
    
                ConfigurationSection aspSection = config.GetSection("system.webServer/asp", "Default Web Site");
                aspSection["appAllowClientDebug"] = true;
                aspSection["appAllowDebugging"] = true;
                aspSection["enableParentPaths"] = true;
                aspSection["scriptErrorSentToBrowser"] = true;
    
                serverManager.CommitChanges();
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-06
      • 1970-01-01
      • 1970-01-01
      • 2016-09-28
      • 2010-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多