Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all websites in IIS c#

Tags:

c#

iis

Is there a way to list all active websites that exist within IIS using c#?

Thanks

Sp

like image 423
Steven Avatar asked Jan 04 '11 12:01

Steven


People also ask

How do I list websites in IIS?

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.

How do I stop a website using PowerShell?

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.


2 Answers

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;
like image 96
Sir Hally Avatar answered Sep 19 '22 11:09

Sir Hally


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.

like image 27
Darin Dimitrov Avatar answered Sep 18 '22 11:09

Darin Dimitrov