Get the current dot net version of my application

2019-06-22 13:06发布

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.

3条回答
该账号已被封号
2楼-- · 2019-06-22 13:31

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

查看更多
一夜七次
3楼-- · 2019-06-22 13:37

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.

查看更多
Luminary・发光体
4楼-- · 2019-06-22 13:40

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.

查看更多
登录 后发表回答