How do I get some information from IIS like Version and some settings like Roles and Services in C #.
* Note: My application is not Web.
How do I get some information from IIS like Version and some settings like Roles and Services in C #.
* Note: My application is not Web.
Information about your IIS can be obtained by using the ADSI . The examples are from IIS 6, but there would be no reason not to work on later versions of IIS.
In this article there are examples of how to get some information and even create websites in IIS .
Also, the excellent article that teaches you how get IIS settings through Active Directory .
This article is also a more targeted effort to read the IIS settings .
One of the likely ways to do this is through queries by WMI
. Some information can be seen on the IIS WMI Provider page. > .
To work with IIS and WMI , you must use the namespace MicrosoftIISv2
. There are some examples here .
Note : If you are using IIS 7, you must enable Compatibility with IIS 6 WMI , so MicrosoftIISv2
can be present .
In this another page shows you some examples of how to get information using WMI
( tested in IIS 6 and Windows Server 2003 ).
I believe you can also get some information with the class Environment
. According to this page , this can also be done using Request.ServerVariables
, example:
lblServerIP.Text = Request.ServerVariables["LOCAL_ADDR"];
lblMachineName.Text = Environment.MachineName;
lblUserDomainName.Text = Environment.UserDomainName.ToString();
lblUserName.Text = Environment.UserName;
lblOSVersion.Text = Environment.OSVersion.ToString();
lblStartTime.Text = (Environment.TickCount / (1000 * 60 * 60)) + "Hours";
lblNowTime.Text = DateTime.Now.ToLongDateString();
lblIISVersion.Text = Request.ServerVariables["SERVER_SOFTWARE"];
lblIsHTTPS.Text = Request.ServerVariables["HTTPS"];
lblPATHS.Text = Request.ServerVariables["PATH_INFO"];
lblPATHS2.Text = Request.ServerVariables["PATH_TRANSLATED"];
lblPORT.Text = Request.ServerVariables["SERVER_PORT"];
lblSessionID.Text = Session.SessionID;
All variables can be viewed on the IIS Server Variables .