Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up ASP settings using Microsoft.Web.Administration

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?

like image 616
Zoltán Tamási Avatar asked Jan 19 '26 10:01

Zoltán Tamási


1 Answers

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.

IIS Configuration Editor

Select section (system.webServer/asp) and configuration file (ApplicationHost.config <location path="Default Web Site/myAppPath">) and make the changes.

enter image description here

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.

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();
        }
    }
}
like image 112
Kul-Tigin Avatar answered Jan 21 '26 06:01

Kul-Tigin