gpt4 book ai didi

c# - 使用 Microsoft.Web.Administration 设置 ASP 设置

转载 作者:行者123 更新时间:2023-11-30 15:57:49 30 4
gpt4 key购买 nike

是否可以使用 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 替代方案?

最佳答案

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

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

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

IIS Configuration Editor

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

enter image description here

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

Script Diaog

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();
}
}
}

关于c# - 使用 Microsoft.Web.Administration 设置 ASP 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44566716/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com