Attribute based routing

What Is Routing?

What Is Routing?
Routing helps us to decide a URL structure and map the URL with the Controller.
There are two types of routing -
1.      Convention based Routing
The three segments that is important for routing is - {controller}/{action}/{id}

Routes can be configured in RouteConfig class. Multiple custom routes can also be configured.
Route must be registered in Application_Start event in Global.ascx.cs file.

An example for Register Routes -
public class RouteConfig
{
    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 }
        );
    }
}

ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.
^