Identify ASP.NET MVC Assembly Version

Introduction:

The MVC  pattern separates of an application into three main parts.
  1. The Model − Collection of classes are working with the business logic.
  2. The View − It is responsible for User Interfaace. It is a  HTML format whose extension is cshtml.
  3. The Controller − Collection of classes are working data logic and business logic.

Description:

Every MVC application contains 3 folders that is controller, View and Model. Every controller contains controller action method which is responsible for create view to transfer data from controller to view through viewdata and viewbag, Tempdata.

Everey model contains some properties and using this model class name reference using namespace inside controller we can access related properties of class for business logic implementation.

In case of entity data model creation that is edmx file automatically creates model class based on table name or reated data base object name and with related properties as same as column name of  that table.

The Way To Find Assembly Version Without Using Code Called Design Time. In the solution explorer, expand "References" folder. Right click on System.Web.Mvc assembly and select "Properties" and you 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 of 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  
                });  
            }  
        }  
    }

Comments

Post a Comment

Popular posts from this blog

Difference Between Sql Operations Studio and Sql Server Management Studio