Routing is a mechanism to process the incoming url that is more descriptive and give desired response. In this case, URL is not mapped to specific files or folder as was the case of earlier days web sites.
Namespace for Routing : System.Web.Routing
Namespace for Routing : System.Web.Routing
There are two types of routing (after the introduction of ASP.NET MVC 5).
- Convention based routing - to define this type of routing, we call
MapRoute
method and set its unique name, url pattern and specify some default values.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Finance", action = "Finance", id = UrlParameter.Optional }
);
}
- Attribute based routing - to define this type of routing, we specify the
Route
attribute in the action method of the controller.
No comments:
Post a Comment