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
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

How does AI transform chaos engineering from an experiment into a critical capability? Learn how to effectively operationalize the chaos.

Data quality isn't just a technical issue: It impacts an organization's compliance, operational efficiency, and customer satisfaction.

Are you a front-end or full-stack developer frustrated by front-end distractions? Learn to move forward with tooling and clear boundaries.

Developer Experience: Demand to support engineering teams has risen, and there is a shift from traditional DevOps to workflow improvements.

Related

  • GDPR Compliance With .NET: Securing Data the Right Way
  • How to Enhance the Performance of .NET Core Applications for Large Responses
  • Zero to AI Hero, Part 3: Unleashing the Power of Agents in Semantic Kernel
  • Developing Minimal APIs Quickly With Open Source ASP.NET Core

Trending

  • AI's Cognitive Cost: How Over-Reliance on AI Tools Impacts Critical Thinking
  • Context Search With AWS Bedrock, Cohere Model, and Spring AI
  • How You Can Use Few-Shot Learning In LLM Prompting To Improve Its Performance
  • Modern Test Automation With AI (LLM) and Playwright MCP
  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.

By 
Pramod Gawande user avatar
Pramod Gawande
·
Aug. 15, 17 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
7.8K 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

  • GDPR Compliance With .NET: Securing Data the Right Way
  • How to Enhance the Performance of .NET Core Applications for Large Responses
  • Zero to AI Hero, Part 3: Unleashing the Power of Agents in Semantic Kernel
  • Developing Minimal APIs Quickly With Open Source ASP.NET Core

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: