简体   繁体   English

使用Microsoft.Web.Administration将AspNetCore参数添加到IIS应用程序

[英]Add AspNetCore argument to IIS application using Microsoft.Web.Administration

I have a need to host multiple instances of an ASP.NET Core application on a server, which each one being configured differently via a command line argument. 我需要在服务器上托管一个ASP.NET Core应用程序的多个实例,每个实例都通过命令行参数进行不同的配置。 The web application instances are managed using a Windows Forms application with the Microsoft.Web.Administration API. 使用Windows窗体应用程序和Microsoft.Web.Administration API来管理Web应用程序实例。

Without using the WinForms app, I was able to get this working with multiple instances by adding arguments with the Configuration Editor for each site in IIS Manager and setting "From" to ApplicationHost.config. 在不使用WinForms应用程序的情况下,我可以通过在IIS管理器中为每个站点的配置编辑器添加参数并将“ From”设置为ApplicationHost.config来处理多个实例。 This sets a different argument for each app instance to use, all while still running from the same ASP.NET Core .exe. 这为每个要使用的应用程序实例设置了一个不同的参数,而所有这些实例仍在同一ASP.NET Core .exe中运行。

What I haven't been able to do is translate this to functionality in the WinForms application. 我无法将其转换为WinForms应用程序中的功能。 When an instance is added via the tool, a new <location> element is added to ApplicationHost.config, and I need to add an < aspNetCore arguments="xxxx" /> child element to it. 通过该工具添加实例后,新的<location>元素将添加到ApplicationHost.config,并且我需要向其中添加< aspNetCore arguments="xxxx" />子元素。

I was able to get this working, I had overlooked the overload of GetSection that would read from a specific location. 我能够使它正常工作,我忽略了从特定位置读取的GetSection的重载。 tt was as simple as this: tt就这么简单:

var aspNetCoreConfig = site.GetWebConfiguration().GetSection("system.webServer/aspNetCore", "<appInstanceName>");

aspNetCoreConfig["arguments"] = "xxxx";

When adding the Application using ServerManager. 使用ServerManager添加应用程序时。 It's important that the web.config for the application itself NOT have an arguments attribute in the <aspNetCore> section. 重要的是,应用程序本身的web.config在<aspNetCore>部分中不要具有arguments属性。 This will override anything set in the Site's web.config or the server's ApplicationHost.config for that location since all application instances share a web.config in their root folder, but can have instance-specific settings configured in their respective <location> sections in a higher-level config. 这将覆盖在站点的web.config或服务器的ApplicationHost.config中针对该位置设置的任何内容,因为所有应用程序实例在其根文件夹中共享一个web.config,但可以在其各自的<location>部分中配置特定于实例的设置更高级别的配置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用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 Express Web服务器 - Unable to launch the IIS Express Web Server after using Microsoft.Web.Administration 使用 Microsoft.Web.Administration 远程管理 IIS 时,身份验证期间出现 COMException - COMException during authentication when managing IIS remotely using Microsoft.Web.Administration IIS 8-FTP隔离提供程序-Microsoft.Web.Administration - IIS 8 - FTP isolation provider - Microsoft.Web.Administration 如何使用Microsoft.Web.Administration命名空间在IIS7中干净地操作Handler Mappings? - How do I manipulate Handler Mappings cleanly in IIS7 using the Microsoft.Web.Administration namespace? 使用Microsoft.Web.Administration将ISAPI筛选器添加到现有站点 - Add an ISAPI Filter to an existing Site with Microsoft.Web.Administration 使用 Microsoft.Web.Administration 以编程方式创建网站 - Using Microsoft.Web.Administration to programmatically create web sites .Net Core和Microsoft.Web.Administration - .Net Core and Microsoft.Web.Administration 停止网站Microsoft.Web.Administration AccessDenied - Stopping WebSite Microsoft.Web.Administration AccessDenied
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM