Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically set "Enable Parent Paths" in IIS7 from C#

I'm trying to setup a website from a c# application and have managed to do everything except access the "ASP" settings. I would like to be able to turn "Enable Parent Paths" on for my site.

I have so far managed everything using Microsoft.Web.Administration, any help would be really appreciated?

The code i have so far is:

var site = sManager.Sites.Add(webSite.SiteName, webSite.PhysicalLocation, webSite.Port);
site.ApplicationDefaults.ApplicationPoolName = webSite.ApplicationPoolName;
site.Bindings.Clear();
site.Bindings.Add(string.Format("{0}:{1}:{2}", webSite.BindingIP, webSite.Port, webSite.HostHeader), "http");

site.ServerAutoStart = true;
sManager.CommitChanges();

Thanks in advance.

like image 494
sonicm Avatar asked Jan 24 '26 10:01

sonicm


1 Answers

You should read this AspSection topic in MSDN and also some basic how to on web adminstrator. Although the "how to" doesn't actually demonstrate it you should be able to cast a section to the AspSection class:

        Configuration config = sManager.GetApplicationHostConfiguration();
        AspSection section = (AspSection)config.GetSection("system.webServer/asp",webSite.SiteName);
        section.EnableParentPaths = true;

if some reason the cast is not allowed you can use the basic attribute approach:

        Configuration config = sManager.GetApplicationHostConfiguration();
        ConfigurationSection section = config.GetSection("system.webServer/asp",webSite.SiteName);
        ConfigurationAttribute enableParentPaths = section.GetAttribute("enableParentPaths");
        enableParentPaths.Value = true;
like image 62
AnthonyWJones Avatar answered Jan 25 '26 23:01

AnthonyWJones



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!