Before going further lets know about what is Attribute Routing ? In MVC 5 this new feature was added and before that we used Convention Routing which looks like this

public static void RegisterRoutes(RouteCollection routes)
{
   routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
   routes.MapRoute(
          name: "Default",
          url: "{controller}/{action}/{id}",
          defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

now imagine you are working on a e-commerce website and you have to define alot of routs for each action in RouteConfig, well you can do it but it will be difficult to debug and its not a clean way thats why Attribute Routing was introduced which gives developers great flexibility and ease.

Enabling Attribute Routing

Its really easy to enable attribute routing, all you have to do is just add

routes.MapMvcAttributeRoutes();

In the RouteConfig file like this

public class RouteConfig  
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapMvcAttributeRoutes();
    }
}

and thats it you have enabled the attribute routing.

Using Attribute Routing

unlike Convention Routing its really easy to use Attribute Routing, for route to work you have to define a custom route in [Route()] Attribute.

public class HomeController : Controller  
{
    [Route("~/Home/Index")]
    public ActionResult Index() { ... }
}

the above route will take you to URL  domainname/home/index