![](/img/trans.png)
[英]IIS: How to create virtualdirectory in website with Microsoft.Web.Administration
[英]IIS - How to edit local config for application with Microsoft.Web.Administration
我可以使用ServerManager创建一个网站,方法是:
iisApplication = site.Applications.Add("/MySite", SomePath);
我要编辑一些属性(但仅特定于此应用程序,而不是站点或服务器范围内的属性)。 使用此代码
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);
提交更改后,我立即收到错误消息
Filename: \\?\C:\inetpub\wwwroot\MySite\web.config
Error: Cannot write configuration file
现在看来,GetWebConfiguration()正在拉入错误的web.config文件,因为我的网站未存储在inetpub中,而是在另一个文件夹中。
如何在本地网站文件夹中编辑web.config? 这是winforms。
我找到了答案-必须使用“位置”路径在更高级别上对其进行编辑:
config = iisManager.GetApplicationHostConfiguration();
ConfigurationSection anonymousAuthenticationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Default Web Site/MySite);
anonymousAuthenticationSection["enabled"] = true;
iisManager.CommitChanges();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.