Getting ASP.NET version used by IIS Web Site


It is easy to get the ASP.NET version installed at the machine level. But it took me some time to figure out ( with the help of others , of course) to get the ASP.NET version used by a given web site in IIS , since side by side is supported by .NET and admin would be able to pick the ASP.NET version from IIS Manager and change it at any time at a granular level.


Here is the code snippet & help I got


String sWebSite = “w3svc/1”
DirectoryEntry site = new DirectoryEntry(“IIS://localhost/” + sWebSite + @”/Root”);
           
            


                    PropertyValueCollection vals = site.Properties[“ScriptMaps”];
                    foreach (string val in vals)
                    {
                        if (val.StartsWith(“.aspx”))
                        {
                            string version = val.Substring(val.IndexOf(“Framework”) + 10, 9);
                            MessageBox.Show(String.Format(“ASP.Net Version on virtual server is {0}”, version));


                        }



                    }
The idea here is to use the  System.DirectoryServices classes which will use IIS ADSI provider.
You need to read the ScriptMap property at your application path. For example if you wanna see the asp.net version for the default web site – read the ScriptMap at LM/W3SVC/1/ROOT/. The script map property is an array of strings. If the app supports asp.net one of those strings will be a mapping of the aspx file extension to the asp.net handler which will a the full path to a DLL. The path will be something like %windir%/Microsoft.NET/Framework/<asp.net ver>/aspnet_isapi.dll. You can get the version out of this string with some simple parsing.



Other approaches from scripts include

1) Running “cscript adsutil.vbs enum w3svc/filters”  (without quotes) from command prompt should list the filters in IIS metabase. You need to change the current directory to c:\inetpub\adminscripts before running this command.


2) %windir%\microsoft.net\framework\v2.0.50902\ASPNET_REGIIS.EXE –lk


Comments (3)

  1. great_scandivavian says:

    Would anyone know how to do this with IIS 7 running under Vista?

    It worked great for my IIS 6 sites but IIS 7 seams to have put a stopper for this trick!

    Any help would be geatly appreciated.

  2. Ray says:

    For IIS7 asp.net version is a property of the app pool in which the application runs, no longer a property of the app/virtual directory directly. Use Microsoft.Web.Administration package to check it

Skip to main content