How to display an assembly version number in a asp.net program

Source: Internet
Author: User
Tags reflection

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 ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.