The ASP.NET Routing module is
responsible for mapping incoming browser requests to particular MVC controller
actions.
Asp.net
Routing is set up in two places
- Web.config
- Global.asax
Web.Config file
Asp.net routing is enabled in your Web.Config file there are 4 sections
in the configuration file that is relevant to routing
- System.web.httpModules Section
- System.web.httphandlers section
- System.webserver.modules section
- System.webserver.handlers section
Note: Without this section routing will not work
Global.asax:
This is a file which contains
event handlers for application life cycle events
For a route table is created in
the application’s global.asax file, which is created during the applications
start event
Exploring Global.asax
In the application Application_Start
function we can see a call to Register Routes
You can see a default route map in the figure.
The Route name could be anything unique.
There is a predefined route map which maps to Controller/Action/id
when you add additional routes kindly remember that the order is important, they needed to be added on top of the default route.
You can see a default route map in the figure.
The Route name could be anything unique.
There is a predefined route map which maps to Controller/Action/id
when you add additional routes kindly remember that the order is important, they needed to be added on top of the default route.
We will add a New Route
Search
The Above
Route Search/ID maps to Controller = Home/ Action Method = Search / ID
Running the Application
No comments:
Post a Comment