How to get IIS information via C #?

4

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.

    
asked by anonymous 23.03.2015 / 20:28

2 answers

2
24.03.2015 / 04:45
3

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 .

    
24.03.2015 / 14:11