concept duplication in category asp.net

This is an excerpt from Manning's book ASP.NET Core in Action.
If that feels a little redundant, like you’ll be duplicating logic and code, then I’m afraid you’re right. It’s one of the unfortunate aspects of web development; the duplication is a necessary evil. Thankfully, ASP.NET Core provides several features to try to reduce this burden.
This is largely a symptom of the greater control attribute routing provides, but there are a few features available to make your life a little easier. In particular, combining route attributes and token replacement can help reduce duplication in your code.
Listing 9.6. Duplication in RouteAttribute templates
public class CarController { [Route("api/car/start")] [Route("api/car/ignition")] [Route("/start-car")] public IActionResult Start() { /* method implementation*/ } [Route("api/car/speed/{speed}")] [Route("/set-speed/{speed}")] public IActionResult SetCarSpeed(int speed) { /* method implementation*/ } }

This is an excerpt from Manning's book ASP.NET MVC 2 in Action.
As powerful as the HtmlHelper extensions for strongly typed views can be, we still introduce quite a bit of duplication in our views if we rely solely on these extensions for generating HTML. For example, if every input element requires a corresponding label, why not always include it? Every user interface is different, so the MVC team can’t predict the layout everyone wants to use for input and label elements. Instead, we can take advantage of a new feature in ASP.NET MVC 2—templates—to enforce a standardized approach to generating HTML.
The MVC pattern gives us separation of concerns between the model, controller, and view, but this pattern didn’t eliminate the need for developers to carefully design their views. With the elimination of code-behind and the addition of a view model object, we can focus strictly on rendering content inside our view. But without careful attention, our views can still slide into a morass of duplication and spaghetti code. We can no longer lean on custom controls to encapsulate view behavior as we did in Web Forms. Instead, ASP.NET MVC provides similar and expanded mechanisms for tackling all levels of duplication in our views.
First, we’ll look at the various forms of duplication we encounter in our views and explore various means of tackling duplication as it arises.
In ASP.NET MVC, the ability to use web controls to encapsulate complex UI elements is all but gone. We can use web controls that don’t take advantage of ViewState, but that renders web controls built for Web Forms mostly useless. Instead, we have to turn to other means to eliminate duplication in our views.

This is an excerpt from Manning's book ASP.NET MVC in Action with MvcContrib, NHibernate, and More.
Remember earlier when we noticed an opportunity to make those other routes more dynamic? This would avoid duplication in the route rules and hopefully make them easier to understand. Armed with tests to back us up, we can now attempt to combine these routes.
To display the view, the authentication filter adds the current user in session to ViewData. Athough we want this common behavior across many actions and views, it would be painful to put this filter on every controller. We would likely forget some controllers. In addition, maintenance of a filter declared on a large group of controllers is duplication that should be avoided. The other filters perform similar operations, and they place relevant information into ViewData so that the views can use the information.
When using Web Forms, we had many different avenues for reducing duplication and providing common visual components. Many of these same avenues exist for MVC; some are new, and some are deprecated. There are at least four ways to consolidate HTML in ASP.NET MVC: