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
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • All Things ASP.NET Core and MVC: Tutorials and Articles
  • Add Watermark Text to Images in ASP.NET MVC
  • OAuth Implicit flow Using Angular 6 and ASP.NET MVC Core
  • Identify ASP.NET MVC Assembly Version

Trending

  • GenAI-Infused ChatGPT: A Guide To Effective Prompt Engineering
  • The Convergence of Testing and Observability
  • A Guide to Data-Driven Design and Architecture
  • Microservices With Apache Camel and Quarkus (Part 5)
  1. DZone
  2. Coding
  3. Frameworks
  4. ASP.NET MVC 6 Routing Technique

ASP.NET MVC 6 Routing Technique

In this tutorial, we explore two new routing techniques introduced to ASP.NET by MVC 6, and explain the benefits they have on your code.

Pramod Gawande user avatar by
Pramod Gawande
·
Aug. 15, 17 · Tutorial
Like (2)
Save
Tweet
Share
6.71K Views

Join the DZone community and get the full member experience.

Join For Free

Before we jump to custom routing, we will have to take a look at the basic changes in MVC6 from MVC5. ASP.NET MVC6 places all startup necessary services, defined and configured dependencies for the application, in a single file, Startup.cs. The Startup.cs file replaces all the functionality of global.asax where we put the middleware and configuration logic.

As we know, the routing actions are getting managed by the Routes.MapRoute method. In ASP.NET MVC 6 Routes.MapRoute, you won’t find this method as a part of Startup.cs file which now contains very few lines of code. You will also notice that there is no ad-hoc configuration file to take care of RouteConfig.cs, WebApiConfig.cs or other intermediate handlers recurrently shipped with the earlier ASP.NET versions and MVC pattern project templates. Startup.cs file has services.AddMvc() and services.UseMvc() methods to handle the routing action.

We can take a look at the current implementation of the UseMvc() method in the application code.

Image title

We can add our own routing using an Attribute Based and/or Convention Based approach. I am using both methods because if we use two approaches together Attribute based routing overrides Convention based routing. Both routings would override the existing default routes defined by the UseMvc() method.

Attribute Based Routing

We have to write code in the controller to implement attribute based routing.

Image title

Convention Based Routing

We have to write code in Startup.cs to implement attribute based routing.

Image title

ASP.NET MVC ASP.NET

Opinions expressed by DZone contributors are their own.

Related

  • All Things ASP.NET Core and MVC: Tutorials and Articles
  • Add Watermark Text to Images in ASP.NET MVC
  • OAuth Implicit flow Using Angular 6 and ASP.NET MVC Core
  • Identify ASP.NET MVC Assembly Version

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: