For a lot of interesting reasons, ASP. NET program, although you can append AssemblyInfo.cs files to the App_Code directory, the version number in the file is always not displayed correctly in front of the user.
If you try to use the following statements like the other. NET application to get the version number in assembly, you'll always get a 0.0.0.0 string.
System.Reflection.Assembly.GetAssembly (this. Gettyp e ()). GetName (). Version.tostring ();
A lot of people can give me a bunch of reasons to tell me how stupid it is to get an assembly version number in a asp.net program, and I understand it very well, and I agree with it, but we still need to do it if we get a pervert's request.
First, add a AssemblyInfo.cs file under the App_Code file, and the content template for the file can be replicated from other. NET Applications.
Second, add the following code to the Application_Start paragraph in the Global.asax file:
Global.asax
void Application_Start (object sender, EventArgs e)
{
// ...
Load Assembly
Application.add ("Assembly", System.Reflection.Assembly.Load ("App_code/assemblyinfo.cs"));
// ...
}
Simply specify the assembly file directly and put it directly into the application cache.
The last is to get the version number in the code, now that you know how to save it, it's easy to take it out:
Versionnumber.text = ((System.Reflection.Assembly) application["Assembly"]). GetName (). Version.tostring ();