How to Detect Iis Version Using C#

How to detect IIS version using C#?

You can get this information from the SERVER_SOFTWARE variable. It will return the following:

Microsoft-IIS/5.0 (Windows 2000)
Microsoft-IIS/5.1 (Windows XP)
Microsoft-IIS/6.0 (Windows 2003 Server)

etc.

If you're using ASP.NET, you can get this string via

Request.ServerVariables["SERVER_SOFTWARE"];

EDIT: It seems that you will have to query the registry to get this information. Take a look at this page to see how.

How to programmatically determine installed IIS version

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.

How to get IIS version in asp.net core

Updated my code to asp.net core 2.2, still not able to get the value of this variable

If you're using asp.net core 2.2 or above, get the IServerVariablesFeature as below:

var serverVars = HttpContext.Features.Get<IServerVariablesFeature>();
var iisVersion = serverVars == null ? null : serverVars["SERVER_SOFTWARE"];

Demo:

Sample Image

how to check iis version on serve programmatically

http://www.codeproject.com/KB/cs/iisdetection.aspx this express how, you should query the registry

Get IIS version or other IIS Server variables in Asp.Net 5?

In fact, My test shows that this code can still work in Asp.net 5, and IIS variables can be obtained.
Sample Image
Here is the code

using Microsoft.AspNetCore.Http.Features;

IServerVariablesFeature serverVars = HttpContext.Features.Get<IServerVariablesFeature>();
string iis_version = serverVars["SERVER_SOFTWARE"];
string app_pool_id = serverVars["APP_POOL_ID"];
string runtime = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;

The Asp.net core version information for IServerVariablesFeature is also mentioned in the document.

Applies to
ASP.NET Core
5.0 3.1 3.0 2.2

So I think you should carefully check the other code in the application, whether it may be a misspelling when referencing variables, or a problem with the installation of Asp.net Core 5.

How to determine whether IIS7 is installed under a local machine

mmmmm looks like you need to search google

http://www.codeproject.com/Articles/18301/Using-Managed-Code-to-Detect-if-IIS-is-Installed-a

http://blogs.iis.net/chrisad/archive/2006/09/01/Detecting-if-IIS-is-installed_2E002E002E00_.aspx

http://geekswithblogs.net/sdorman/archive/2007/03/01/107732.aspx



Related Topics



Leave a reply



Submit