c#-使用Microsoft.Web.Administration设置ASP设置
作者:互联网
是否可以使用Microsoft.Web.Administration包为给定位置配置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>配置编辑器
屏幕快照是针对默认网站采取的,但是对于像您这样的虚拟应用程序,其步骤相同.
选择部分(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();
}
}
}
标签:iis,asp-classic,c 来源: https://codeday.me/bug/20191111/2018657.html