Welcome to MSDN Blogs Sign in | Join | Help

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

Published Thursday, January 05, 2006 10:29 PM by meysun
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Vista & IIS 7 breaks the suggested trick

Sunday, February 25, 2007 5:09 AM by great_scandivavian

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.

# regarding checking the .net version for default website | keyongtech

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker