DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Reduce Frontend Complexity in ASP.NET Razor Pages Using HTMX
  • Design Automation in Closure Engineering: Building Parametric Assemblies With CATIA and VB Scripting
  • The Hidden World of Exit Codes: Tiny Integers With Big Meanings
  • GDPR Compliance With .NET: Securing Data the Right Way

Trending

  • Treat Salesforce Configuration Like Code: Release Discipline in a Copado Pipeline
  • Why Vulnerability Management Fails Without Reliable Asset Data
  • Solving Comprehension Debt in AI-Generated Codebases
  • Part 1: Building Governed MCP Tool Services With Quarkus LangChain4j and Goose

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Frameworks
  4. Identify ASP.NET MVC Assembly Version

Identify ASP.NET MVC Assembly Version

In this post, we'll learn to check our ASP.NET MVC version installed in our system using C# during runtime and manually customize an error page in ASP.NET/ ASP.NET MVC 5.

By 
Satyaprakash Samantaray
·
Jun. 12, 18 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
15.8K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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:

  • Installed ASP.NET MVC Assembly Version using C#

ASP.NET MVC ASP.NET Assembly (CLI)

Opinions expressed by DZone contributors are their own.

Related

  • Reduce Frontend Complexity in ASP.NET Razor Pages Using HTMX
  • Design Automation in Closure Engineering: Building Parametric Assemblies With CATIA and VB Scripting
  • The Hidden World of Exit Codes: Tiny Integers With Big Meanings
  • GDPR Compliance With .NET: Securing Data the Right Way

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook