Identify ASP.NET MVC Assembly Version

Introduction:

The MVC  pattern separates an application into three main parts.

  1. The Model − Collection of classes that are working with the business logic.
  2. The View − It is responsible for the User Interface. It is an HTML format whose extension is .cshtml.
  3. The Controller − Collection of classes that are working data logic and business logic.

Description:

Every MVC application contains 3 folders: Controller, View, and Model.

Every controller contains controller action methods which are responsible for creating the view to transferring data from the controller to view through ViewData, ViewBag, and TempData.

Every model contains some properties and by using this model class name reference while using namespaces inside a controller we can access related properties of classes for business logic implementation.

In the case of the entity data model creation, an edmx file automatically creates a model class based on the table name or related database object name and with properties related to the column name of that table.

The Way to Find Assembly Version Without Using Code, Called Design Time

In the solution explorer, expand the "References" folder. Right-click on the System.Web.Mvc assembly and select "Properties" to can find the version.

Steps to Be Followed at Runtime Using Code:

Step 1:

Create a controller named “Home.”

Add the code given below in HomeController.cs for better results, as expected. 

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
using System.Web.Mvc;  
namespace Mvc_Version.Controllers {  
    public class HomeController: Controller {  
        //  
        // GET: /Home/  
        public string Version() {  
            return "<h2>The Installed Mvc Version In your System Is : " + typeof(Controller).Assembly.GetName().Version.ToString() + "</h2>";  
        }  
    }  
}  

Code Description:

We mentioned the controller action method version in HomeController.cs.

For this, we should change the action method name in RouteConfig.cs for better loading of the page. For the first time, we will make it a start page.

Add the highlighted code in your file, RouteConfig.cs. 

    using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.Web;  
    using System.Web.Mvc;  
    using System.Web.Routing;  
    namespace Mvc_Version {  
        public class RouteConfig {  
            public static void RegisterRoutes(RouteCollection routes) {  
                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");  
                routes.MapRoute(name: "Default", url: "{controller}/{action}/{id}", defaults: new {  
                    controller = "Home", action = "Version", id = UrlParameter.Optional  
                });  
            }  
        }  
    }   

Output

The expected output is shown below.

http://localhost:49952/Home/Version

Home - Controller name

Version - Controller action method

Image title

Summary:

 

 

 

 

Top