简体   繁体   中英

How to know which version of ASP.net it is?

How can we know which version of ASP.NET it is built in by looking into the ASP.NET project. Could somebody please list different ways to identify the version?

Thank you

You need to be careful with the approach you use here because some updates to the .NET framework under ASP.NET will seemingly run under previous version numbers. For example;

  • ASP.NET 2.0 websites might be running v2.0 or v3.5 frameworks and
  • ASP.NET 4.0 websites might be running v4.0 or v4.5 frameworks

There are a couple of ways to check the exact version you are running, on your web page add:

<%= System.Environment.Version.ToString() %>

As an example;

  • if you have v4.0 installed you'll see v4.0.30319.1008
  • if you have v4.5 installed you'll see v4.0.30319.34209

That will get the currently running version. You can check the registry for all installed versions at:

HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full

Within this location look at the Version node.

  • if you have v4.0 installated you will see v4.0.30319
  • if you have v4.5 installated you will see v4.5.51209

Open the .csproj file and look inside of it. You'll see something like this:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    ...
    <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    ...
  </PropertyGroup>
</Project>

ProjectTypeGuids is what identifies what kind of a Visual Studio project this thing is - an ASP.NET Application like in this example or some other type of a project. Different versions will also imply different GUIDs. You just have to find out what these IDs refer to.

I got this to work fine on ASP.NET v4.5, hope it helps. You may have to tweak it a bit for your system.

<%@ Page Language="VB" Debug="true" %>
<% 
Dim cmnNETver, cmnNETsplt, dotNETver, dotNETsplt, aspNETver, aspNETsplt As Object
Dim osVersion, dotNETfil, aspNETfil, cmnNETfix, dotNETpth, dotNETtxt, dotNETfix, aspNETpth, aspNETtxt, aspNETfix As String

osVersion = System.Environment.OSVersion.ToString

dotNETfil = "ngen.exe"
aspNETfil = "clr.dll"

cmnNETver = System.Environment.Version.ToString
cmnNETsplt = cmnNETver.Split(".")
cmnNETfix = cmnNETsplt(0) & "." & cmnNETsplt(1) & "." & cmnNETsplt(2)

dotNETpth = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Windows) & "\Microsoft.NET\Framework64\v" & cmnNETfix & "\" & dotNETfil

If System.IO.File.Exists(dotNETpth) Then
  dotNETver = System.Diagnostics.FileVersionInfo.GetVersionInfo(dotNETpth)
  dotNETtxt = dotNETver.FileVersion.ToString
  dotNETsplt = dotNETtxt.Split(" ")
  dotNETfix = dotNETsplt(0) & " per " & dotNETfil
Else
  dotNETfix = "Path not found... No version found..."
End If

aspNETpth = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Windows) & "\Microsoft.NET\Framework64\v" & cmnNETfix & "\" & aspNETfil

If System.IO.File.Exists(aspNETpth) Then
  aspNETver = System.Diagnostics.FileVersionInfo.GetVersionInfo(aspNETpth)
  aspNETtxt = aspNETver.FileVersion.ToString
  aspNETsplt = aspNETtxt.Split(" ")
  aspNETfix = aspNETsplt(0) & " per " & aspNETfil
Else
  aspNETfix = "Path not found... No version found..."
End If

Response.Write("Common MS.NET version: " & cmnNETver & "<br>")
Response.Write("Common MS.NET path number: " & cmnNETfix & "<br>")
Response.Write("Microsoft.NET full path: " & dotNETpth & "<br>")
Response.Write("<b>Microsoft.NET version: " & dotNETfix & "</b><br>")
Response.Write("ASP.NET full path: " & aspNETpth & "<br>")
Response.Write("<b>ASP.NET version: " & aspNETfix & "</b><br>")
Response.Write("OS version: " & osVersion & "<br>")
%>

In the aspNETpath = "Framework64" can also be "Framework" worked either way for me, same output, output looks like this for me:

Common MS.NET version: 4.0.30319.42000
Common MS.NET path number: 4.0.30319
Microsoft.NET full path: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe
Microsoft.NET version: 4.6.1586.0 per ngen.exe
ASP.NET full path: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
ASP.NET version: 4.7.2110.0 per clr.dll
OS version: Microsoft Windows NT 10.0.14393.0

Cheers, AG

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM