使用 Microsoft.Web.Administration 设置 ASP 设置
Setting up ASP settings using Microsoft.Web.Administration
是否可以使用 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 > 配置编辑器
为默认网站拍摄了屏幕截图,但对于像您这样的虚拟应用程序,步骤是相同的。
Select 部分 (system.webServer/asp
) 和配置文件 (ApplicationHost.config <location path="Default Web Site/myAppPath">
) 并进行更改。
进行更改后不要单击应用,只需单击生成脚本。这将打开一个对话框,其中包含一些准备好用于以编程方式进行更改的脚本。
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();
}
}
}
是否可以使用 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 > 配置编辑器
为默认网站拍摄了屏幕截图,但对于像您这样的虚拟应用程序,步骤是相同的。
Select 部分 (system.webServer/asp
) 和配置文件 (ApplicationHost.config <location path="Default Web Site/myAppPath">
) 并进行更改。
进行更改后不要单击应用,只需单击生成脚本。这将打开一个对话框,其中包含一些准备好用于以编程方式进行更改的脚本。
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();
}
}
}