posted 9/19/2011 by Raghav Khunger
In this blog I will show how to detect the IIS version using C#. We are going to make use of RegistryKey class which is the encapsulation for registry. Below is the sample code to detect the IIS version:
using System; using Microsoft.Win32; namespace Sample { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Version version = GetIISVersion(); Response.Write(version); } public Version GetIISVersion() { using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\InetStp", false)) { if (key == null) return new Version(0, 0); int majorVersion = (int)key.GetValue("MajorVersion", -1); int minorVersion = (int)key.GetValue("MinorVersion", -1); if (majorVersion == -1 || minorVersion == -1) return new Version(0, 0); return new Version(majorVersion, minorVersion); } } } }
What kind of email newsletter would you prefer to receive from CodeAsp.Net?18