Is it possible to configure asp
settings for a given location
using the Microsoft.Web.Administration
package?
I'd like to programatically add the following section to a local IIS applicationHost.config
file.
<configuration>
...
<location path="Default Web Site/myAppPath">
<system.webServer>
<asp appAllowClientDebug="true" appAllowDebugging="true" enableParentPaths="true" scriptErrorSentToBrowser="true" />
</system.webServer>
</location>
</configuration>
I cannot find any way, as this section doesn't belong to any site or application which are possible to maintain using this package.
If not, are there any more feature-rich alternatives to Microsoft.Web.Administration
?
It's possible. There's even a wizard that may help you to create such scripts from the IIS Manager GUI if you have Administration Pack installed on your server.
IIS Manager > Sites > Default Web Site > myAppPath > Configuration Editor
Screenhots were taken for Default Web Site but the steps are the same for a virtual application like yours.
Select section ( system.webServer/asp
) and configuration file ( ApplicationHost.config <location path="Default Web Site/myAppPath">
) and make the changes.
After making the changes do not click Apply , just click the Generate Script . This will open a dialog with some scripts ready to use to make changes programmatically.
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();
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.