Get the current dot net version of my application

耗尽温柔 提交于 2019-12-10 14:12:16

问题


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.


回答1:


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.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/8519478/get-the-current-dot-net-version-of-my-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!