![](/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.