Paras
Paras

Reputation: 3067

Get the current dot net version of my application

How do I get the running dot net version of my asp.net application.

I tried the solution from here

Is there an easy way to check the .NET Framework version?

It gives the highest version installed but I need the running version.

Upvotes: 8

Views: 6944

Answers (3)

Mohan Kumar
Mohan Kumar

Reputation: 6056

Hope this one helps,

DirectoryEntry site = new DirectoryEntry(@"IIS://localhost/w3svc/1/Root");
PropertyValueCollection values = site.Properties["ScriptMaps"];
foreach (string val in values)
{
    if (val.StartsWith(".aspx"))
    {
        string version = val.Substring(val.IndexOf("Framework") + 10, 9);
        MessageBox.Show(String.Format("ASP.Net Version is {0}", version));
    }
}

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//aspnet_isapi.dll.

You can get the version out of this string with some simple parsing.

Upvotes: -6

Maheep
Maheep

Reputation: 5605

Use Environment.Version for getting the run time version. It will give the version number of .Net CLR which is being used for executing current application.

You need to be careful here, it will only return run time version not framework version. The CLR for .NET 3.0 and .NET 3.5 is the same CLR from .NET 2.0.

Upvotes: 10

Pranay Rana
Pranay Rana

Reputation: 176896

Use Environment.Version - it gives you the exact version of .NET running the application.

Upvotes: 6

Related Questions