本文介绍了如何确定安装IIS版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你会在preferred方式编程方式确定哪些当前已安装的Microsoft Internet信息服务(IIS)的版本是?

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

我知道,它可以通过查看HKEY_LOCAL_MACHINE \ SYSTEM的MajorVersion键\ CURRENTCONTROLSET \ SERVICES \ W3SVC \参数中找到。

I know that it can be found by looking at the MajorVersion key in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters.

这将是这样做的的推荐的方式,或者是有提供给.NET开发的任何安全或更漂亮的方法?

Would this be the recommended way of doing it, or is there any safer or more beautiful method available to a .NET developer?

推荐答案

您可以建立一个WebRequest的,它在回传的IP地址发送到端口80,并获得服务器的HTTP标头。

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.

这篇关于如何确定安装IIS版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 04:59