简体   繁体   English

IIS-如何使用Microsoft.Web.Administration编辑应用程序的本地配置

[英]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.

相关问题 IIS:如何使用Microsoft.Web.Administration在网站中创建虚拟目录 - IIS: How to create virtualdirectory in website with Microsoft.Web.Administration 如何使用Microsoft.Web.Administration添加子应用程序? - How to add child application using Microsoft.Web.Administration? 使用Microsoft.Web.Administration库创建IIS应用程序创建两个应用程序而不是一个 - IIS application creation by using Microsoft.Web.Administration library creates two application instead of one 使用 Microsoft.Web.Administration 将应用程序池添加到 iis C# - Add Application Pool to iis C# using Microsoft.Web.Administration IIS 8的Microsoft.Web.Administration不会显示所有站点 - Microsoft.Web.Administration for IIS 8 does not display all sites Microsoft.Web.Administration Ssl 证书未在 iis 管理器中选择 - Microsoft.Web.Administration Ssl cert not selected in iis manager 如何在Windows 2003构建计算机上针对Microsoft.Web.Administration(IIS 7.x)进行构建? - How can I build against Microsoft.Web.Administration (IIS 7.x) on a Windows 2003 build machine? Microsoft.Web.Administration-ApplicationHost.Config中带有httpError的NullReferenceException - Microsoft.Web.Administration - NullReferenceException with httpErrors in ApplicationHost.Config 如何使用Microsoft.Web.Administration命名空间在IIS7中干净地操作Handler Mappings? - How do I manipulate Handler Mappings cleanly in IIS7 using the Microsoft.Web.Administration namespace? 如何正确使用Microsoft.Web.Administration从网页启动应用程序池? - how to use Microsoft.Web.Administration properly to start an application pool from a web page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM