---
title: "What is the advantage of defining route structures in the code?"  
description: "What is the advantage of defining route structures in the code?"  
author: "Anupam Mishra"  
published: 2016-02-07  
updated: 2020-09-24  
canonical: https://www.mindstick.com/interview/22980/what-is-the-advantage-of-defining-route-structures-in-the-code  
category: "asp.net"  
tags: ["c#", "asp.net", "asp.net mvc"]  
reading_time: 2 minutes  

---

# What is the advantage of defining route structures in the code?

Most of the time developers code in the action methods. Developers can see the URL structure right upfront rather than going to the “**routeconfig.cs**” and see the lengthy codes. For instance in the below code the developer can see right upfront that the “**GotoForm**” action can be invoked by four different URL structure.\
\
This is much user friendly as compared to scrolling through the “**routeconfig.cs**” file and going through the length line of code to figure out which URL structure is mapped to which action.\

```
public class HomeController : Controller{       [Route("Home/About")]       [Route("Home/Account Details")]       [Route("Home/Our Team")]       [Route("Home/About Company")]       public ActionResult GotoForm()       {           return View();       }}
```

## Answers

### Answer by Anupam Mishra

Most of the time developers code in the action methods. Developers can see the URL structure right upfront rather than going to the “**routeconfig.cs**” and see the lengthy codes. For instance in the below code the developer can see right upfront that the “**GotoForm**” action can be invoked by four different URL structure.\
\
This is much user friendly as compared to scrolling through the “**routeconfig.cs**” file and going through the length line of code to figure out which URL structure is mapped to which action.\

```
public class HomeController : Controller{       [Route("Home/About")]       [Route("Home/Account Details")]       [Route("Home/Our Team")]       [Route("Home/About Company")]       public ActionResult GotoForm()       {           return View();       }}
```


---

Original Source: https://www.mindstick.com/interview/22980/what-is-the-advantage-of-defining-route-structures-in-the-code

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
