gpt4 book ai didi

c# - 从 C# 以编程方式在 IIS7 中设置 "Enable Parent Paths"

转载 作者:行者123 更新时间:2023-11-30 16:23:55 25 4
gpt4 key购买 nike

我正在尝试通过 C# 应用程序设置一个网站,并且已经设法完成了除访问“ASP”设置之外的所有操作。我希望能够为我的站点启用“启用父路径”。

到目前为止,我已经使用 Microsoft.Web.Administration 管理了所有内容,非常感谢任何帮助?

我目前的代码是:

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();

提前致谢。

最佳答案

你应该阅读这个AspSection MSDN 中的主题以及一些 basic how to on web adminstrator .尽管“操作方法”实际上并未演示它,但您应该能够将一个部分转换到 AspSection 类:

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

如果由于某种原因不允许转换,您可以使用基本属性方法:

        Configuration config = sManager.GetApplicationHostConfiguration();
ConfigurationSection section = config.GetSection("system.webServer/asp",webSite.SiteName);
ConfigurationAttribute enableParentPaths = section.GetAttribute("enableParentPaths");
enableParentPaths.Value = true;

关于c# - 从 C# 以编程方式在 IIS7 中设置 "Enable Parent Paths",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11136792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com