Is there a way to list all active websites that exist within IIS using c#?
Thanks
Sp
The Get-IISSite cmdlet gets information about Internet Information Services (IIS) web sites and their current status and other key information. If you a request a specific site or a comma delimited list of sites, only those whose names are passed as an argument are returned. Otherwise all the websites are returned.
To manage the site in PowerShell, you have two cmdlets to work with – Start-IISSite and Stop-IISSite . These two cmdlets work similarly to how the Stop-Service and Start-Service cmdlets operate. Stopping a website is similar to stopping a Windows service.
For IIS 7 you can use Microsoft.Web.Administration.dll (C:\Windows\System32\inetsrv) and the following code
var iisManager = new ServerManager();
SiteCollection sites = iisManager.Sites;
Here's an article explaining how this could be done using classes from the System.DirectoryServices namespace as well as the Microsoft.Web.Administration namespace which was introduced with IIS 7.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With