Asp net core 5 mvc version number in footer

ASP.NET is a widely used programming language for developing web applications. It provides a powerful framework for building dynamic and interactive websites. One in web is to display the number of the application in the footer. In this article, we will explore how to achieve this using ASP.NET Core 5 MVC.

To begin with, let's create a new ASP.NET Core 5 MVC project. Open Visual Studio and select “Create a new project.” Choose the ASP.NET Core Web Application template and provide a name for your project. Select the MVC template and click on “Create.”

Once the project is , open the `/Shared/_Layout.cshtml` file. This file contains the layout for all the views in your application. Locate the footer section in the layout file and add the following code inside it:

“`csharp

        
            © @DateTime.Now.Year - My Awesome App v1.0
        
    

“`

In the above code, we are using the `@DateTime.Now.Year` to display the current year dynamically. You can replace “My Awesome App v1.0” with your application name and version number.

Save the changes and run your application. You will now see the footer section with the current year and the application version number.

Dynamic Version Number

In some cases, you may want to display the version number dynamically based on the information of your application. To achieve this, you can use the `Assembly.GetExecutingAssembly().GetName().Version` .

Open the `Startup.cs` file and add the following code inside the `ConfigureServices` method:

“`csharp
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_5_0);
services.AddSingleton();
“`

Next, open the `Views/Shared/_Layout.cshtml` file and the footer section code as follows:

“`csharp
@using System.Reflection
@ IHttpContextAccessor HttpContextAccessor

        
            © @DateTime.Now.Year - My Awesome App v@Assembly.GetExecutingAssembly().GetName().Version
        
    

“`

In the above code, we are injecting the `IHttpContextAccessor` to access the current HttpContext. Then, we are using the `Assembly.GetExecutingAssembly().GetName().Version` property to retrieve the version number dynamically.

Save the changes and run your application. Now, the footer section will display the current year and the dynamically retrieved version number of your application.

By following the above steps, you can easily display the version number of your ASP.NET Core 5 MVC application in the footer. Whether you choose to display a static version number or retrieve it dynamically, it provides a way to inform your users about the current version of your application.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents