2

I'm creating a .NET Core 2.1 Web API project (with Angular 7 front-end) where I'm using the Microsoft.Web.Administration API to pull information from remote IIS web servers (mainly listing websites, applications, app-pools, etc.):

https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.administration?view=iis-dotnet

As a quick note, here is how I am instantiating a remote-IIS server object, a ServerManager object:

To create the ServerManager object (the IIS 'container' object, so-to-speak) I use one of the hidden constructors where I pass the remote IIS server's applicationHost.config file path to it (located at C:\Windows\System32\inetsrv\config -- default location). I'm doing this because I receive COM-related issues when I use the ServerManager.OpenRemote(string server_ip) method.

Anyways, whenever I'm trying to use the ServerManager's, Site's, and Application's GetWebConfiguration methods to get the Web.config files for each IIS object, each of the aforementioned object's GetWebConfig methods fail. The app doesn't crash when I run my code, but upon object inspection in the debugger, this is the following error listed:

my_siteWebConfig.RootSectionGroup = 'my_siteWebConfig.RootSectionGroup' threw an exception of type 'System.IO.DirectoryNotFoundException'

It looks like the GetWebConfiguration code is looking for the site/application's web.config file in an non-existent directory. Debugger shows that the ConfigurationPathToEdit equals "MACHINE/WEBROOT/APPHOST/my_site". It's looking in the directory where the applicationHost.Config file is (the global IIS settings file location). However, my websites' & applications' web.config files are stored under the D:\ drive at D:\MyCompany. Is there a way for the GetWebConfiguration methods to look at a directory other than the default applicationHost.Config directory for the config files?

Sorry if this is a bit confusing. Thanks for any help, and let me know if something isn't clear. Thank you.

John M. Wright
  • 4,477
  • 1
  • 43
  • 61
Shawn Dell
  • 21
  • 2
  • You can look at this link: `https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.administration.servermanager.getwebconfiguration?view=iis-dotnet` Seems like you just need to provide the web app name: `ServerManager.GetWebConfiguration("WEB APP NAME")` – Icculus018 May 20 '19 at 21:30
  • Install IIS Administration API on those IIS machines so that you can call REST API https://learn.microsoft.com/en-us/iis-administration/ `Microsoft.Web.Administration` is in general not designed for .NET Core. – Lex Li May 20 '19 at 22:47
  • @kristech That's exactly what I'm doing - I provide the "APP NAME" or "SITE NAME" to the GetWebConfiguration method on the ServerManager object, but I receive the "System.IO.DirectoryNotFoundException," and it's because it's looking in this directory for the web.config: MACHINE/WEBROOT/APPHOST/SITE", but my web.config is actually located in a folder under my D drive. The code explicitly checks MACHINE/WEBROOT directory though, and I don't know why. – Shawn Dell May 21 '19 at 13:24
  • @LexLi I've been browsing the source code of IIS Administration API. I'm doing things similar except remotely. I'm trying to avoid having to install that API/microservice on over 20 servers... – Shawn Dell May 21 '19 at 13:29
  • You probably cannot do 'remotely" as Microsoft's code did not indicate the feasibility. – Lex Li May 21 '19 at 13:30
  • @LexLi You can do this remotely... There's an OpenRemote() method on the ServerManager object. I'm able to get the websites, apps, etc from remote IIS servers, but it's just this GetWebConfiguration method that doesn't work because I'm not storing my web.config in the directory they're checking. – Shawn Dell May 21 '19 at 13:33

0 Answers0