[英]IIS - How to edit local config for application with Microsoft.Web.Administration
I can create a website using ServerManager just fine using: 我可以使用ServerManager创建一个网站,方法是:
iisApplication = site.Applications.Add("/MySite", SomePath);
I want to edit some properties (but only specific to this application, not site or server-wide). 我要编辑一些属性(但仅特定于此应用程序,而不是站点或服务器范围内的属性)。 Using this code
使用此代码
Configuration config = iisApplication.GetWebConfiguration();
ConfigurationSection defaultDocumentSection = config.GetSection("system.webServer/defaultDocument");
ConfigurationElementCollection documents = defaultDocumentSection.GetCollection("files");
documents.Clear();
ConfigurationElement document = documents.CreateElement();
document["value"] = "MyFile.aspx";
documents.Add(document);
As soon as I commit changes I get the error 提交更改后,我立即收到错误消息
Filename: \\?\C:\inetpub\wwwroot\MySite\web.config
Error: Cannot write configuration file
Now it looks as though GetWebConfiguration() is pulling in the wrong web.config file because my site is not stored in inetpub, it is in a different folder. 现在看来,GetWebConfiguration()正在拉入错误的web.config文件,因为我的网站未存储在inetpub中,而是在另一个文件夹中。
How do I edit web.config in the local website folder? 如何在本地网站文件夹中编辑web.config? This is winforms.
这是winforms。
I found the answer - it has to be edited at a higher level using the 'location' path: 我找到了答案-必须使用“位置”路径在更高级别上对其进行编辑:
config = iisManager.GetApplicationHostConfiguration();
ConfigurationSection anonymousAuthenticationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Default Web Site/MySite);
anonymousAuthenticationSection["enabled"] = true;
iisManager.CommitChanges();
please check this link 请检查此链接
Creating a new website programmatically on IIS using ASP.NET and C# 使用ASP.NET和C#在IIS上以编程方式创建新网站
Hope it helps you. 希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.