I got a task of creating an Web application in C# ,which fetches IIS and App Pool details of Website hosted in the remote server(same location).Any idea or help is well appreciated!!!
-Renji
I got a task of creating an Web application in C# ,which fetches IIS and App Pool details of Website hosted in the remote server(same location).Any idea or help is well appreciated!!!
-Renji
This is somehow a broad question, but in order to help here are some points you can start from:
System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName()
I guess this is enough for you to start exploring everything related to IIS, hope it helps.
I was also having the same requirement. On doing so many trail and error approach I got the result.
public static SortedDictionary<string,string> GetApplicationPoolNames ( string mname = null )
{
try
{
ServerManager manager = new ServerManager ();
SortedDictionary<string,string> ApplicationPoolStatus = new SortedDictionary<string,string> ();
if (string.IsNullOrEmpty (mname))
mname = System.Environment.MachineName;
string appPoolName = string.Empty;
manager = ServerManager.OpenRemote (mname);
ApplicationPoolCollection applicationPoolCollection = manager.ApplicationPools;
foreach (ApplicationPool applicationPool in applicationPoolCollection)
{
if (!string.IsNullOrEmpty (applicationPool.Name))
{
if (!ApplicationPoolStatus.ContainsKey (applicationPool.Name))
{
ApplicationPoolStatus.Add (applicationPool.Name,string.Empty);
}
ApplicationPoolStatus[applicationPool.Name] = applicationPool.State.ToString ();
}
}
return ApplicationPoolStatus;
}
catch (Exception)
{
throw;
}
}
public SortedDictionary<string,string> ShowApplicationPoolDatas ()
{
SortedDictionary<string,string> ApplicationPoolStatus = new SortedDictionary<string,string> ();
var domain = this.HttpContext.Request.Url.Host;
DirectoryEntry Services = new DirectoryEntry ("IIS://"+ domain + "/W3SVC/APPPOOLS");
foreach (DirectoryEntry Entry in Services.Children)
{
if (!string.IsNullOrEmpty (Entry.Name))
{
if (!ApplicationPoolStatus.ContainsKey (Entry.Name))
{
ApplicationPoolStatus.Add (Entry.Name,string.Empty);
}
}
var intStatus = (Int32)Entry.InvokeGet ("AppPoolState");
switch (intStatus)
{
case 2:
ApplicationPoolStatus[Entry.Name] = "Running";
break;
case 4:
ApplicationPoolStatus[Entry.Name] = "Stopped";
break;
default:
ApplicationPoolStatus[Entry.Name] = "Unknown";
break;
}
}
return ApplicationPoolStatus;
}