You are looking for ServerManager (Microsoft.Web.Administration) which provides read and write access to the IIS 7.0 configuration system.
(FIND in Forlder : C:\Windows\System32\inetsrv )
using (ServerManager serverManager = new ServerManager())
{
var appPools = serverManager.ApplicationPools;
foreach (ApplicationPool appPool in appPools)
{
Console.WriteLine(appPool.Name)
}
}
(FIND in Forlder : C:\Windows\System32\inetsrv )
// Snippet
using (ServerManager serverManager = new ServerManager()) {
var sites = serverManager.Sites;
foreach (Site site in sites) {
Console.WriteLine(site.Name); // This will return the WebSite name
}
You can also use LINQ to query the ServerManager.Sites collection (see example below)
// Start all stopped WebSites using the power of Linq :)
var sites = (from site in serverManager.Sites
where site.State == ObjectState.Stopped
orderby site.Name
select site);
foreach (Site site in sites) {
site.Start();
}
Note : Microsoft.Web.Administration works only with IIS7.
And RUN VisualStudio with RUN AS ADMINISTRATOR
===
Với ApplicationPool
{
var appPools = serverManager.ApplicationPools;
foreach (ApplicationPool appPool in appPools)
{
Console.WriteLine(appPool.Name)
}
}
No comments:
Write comments