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:
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.
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
How to Get All the Possible 3 Letter Permutations
In C# Wpf, Why Is My Tabcontrol's Selectionchanged Event Firing Too Often
How to Add Text to a Wpf Label in Code
Getting Selected Value of a Combobox
C# - How to Prevent Mousewheel-Scrolling in My Combobox
Update Float Array from C++ Native Plugin
How to Convert Xml to JSON Using C#/Linq
C# Fill Combo Box from SQL Datatable
Are Java and C# Regular Expressions Compatible
Entity Framework Initialization Is Slow -- What How to Do to Bootstrap It Faster
How Does Wpf Inotifypropertychanged Work
How to Display the Output of SQL "Print" Command in C#
Duplicate Key Exception from Entity Framework
Rijndael 256 Encrypt/Decrypt Between C# and PHP
Dependency Injection with a Static Logger, Static Helper Class