How to programmatically determine installed IIS version

后端 未结 6 1953
别那么骄傲
别那么骄傲 2021-01-17 20:27

What would the preferred way of programmatically determining which the currently installed version of Microsoft Internet Information Services (IIS) is?

I know that i

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-17 21:07

    You could build a WebRequest and send it to port 80 on a loopback IP address and get the Server HTTP header.

    HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://127.0.0.1/");
    HttpWebResponse myHttpWebResponse = null;
    try
    {
        myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
    }
    catch (WebException ex)
    {
        myHttpWebResponse = (HttpWebResponse)ex.Response;
    }
    string WebServer = myHttpWebResponse.Headers["Server"];
    myHttpWebResponse.Close();
    

    Not sure if that's a better way of doing it but it's certainly another option.

提交回复
热议问题