-3

How I can check which ASP.NET 4.5 install on IIS in C#. How to detect IIS version

tanks

1 Answers1

0

A reminder: calls like below should not be exposed publicly (e.g. on the web), because giving away version info may lead to vulnerabilities being exploited.

Having said that... here goes:

public string IISVersion()
{
    var v = System.Web.HttpRuntime.IISVersion;
    return string.Format("{0}.{1}", v.Major, v.Minor);
}

public string Get45orHigherFromRegistry()
{
    // Based on code found here: https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx
    using (RegistryKey ndpKey = RegistryKey
        .OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)
        .OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full\\"))
    {
        var versionInfo = ndpKey != null && ndpKey.GetValue("Release") != null
            ? CheckFor45DotVersion((int)ndpKey.GetValue("Release"))
            : "4.5 or later is <b>not detected</b>.";

        return ".NET Framework Version:<br>" + versionInfo;
    }
}

private static string CheckFor45DotVersion(int releaseKey)
{
    // Based on code found here: https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx
    if (releaseKey >= 394271) return "4.6.1 (installed on Windows OS versions other than Windows 10)";
    if (releaseKey >= 394254) return "4.6.1 (installed on Windows 10)";
    if (releaseKey >= 393297) return "4.6 (installed on Windows OS versions other than Windows 10)";
    if (releaseKey >= 393295) return "4.6 (installed with Windows 10)";
    if (releaseKey >= 379893) return "4.5.2";

    var SupportHasEnded = "<br>NOTE: Official MS support for this version has ended on January 12, 2016. You should upgrade to 4.5.2 or higher.";

    if (releaseKey >= 378758) return "4.5.1 (installed on Windows 8, Windows 7 SP1, or Windows Vista SP2)" + SupportHasEnded;
    if (releaseKey >= 378675) return "4.5.1 (installed with Windows 8.1)" + SupportHasEnded;
    if (releaseKey >= 378389) return "4.5" + SupportHasEnded;

    return "4.5/4.6/4.* with unknown release key '" + releaseKey + "'";
}
Peter B
  • 22,460
  • 5
  • 32
  • 69