My mind is somehow blank. How do I do this:
I have a RegistrationController
and want the URL /register
to hit the action Register
on that controller. What do I have to add as a map route in global.asax?
Basic Controllers You can define a route to this controller method like so: use App\Http\Controllers\UserController; Route::get('/user/{id}', [UserController::class, 'show']);
When an MVC application first starts, the Application_Start() method is called. This method, in turn, calls the RegisterRoutes() method. The RegisterRoutes() method creates the route table. The default route table contains a single route (named Default).
Typical URL Patterns in MVC Applications URL patterns for routes in MVC Applications typically include {controller} and {action} placeholders. When a request is received, it is routed to the UrlRoutingModule object and then to the MvcHandler HTTP handler.
In the custom routing mode MVC sites respond to incoming requests using standard ASP.NET routing. Page URLs are determined by the routes that you register into your MVC application's routing table.
Actually, what you want is this:
routes.MapRoute(
"RegisterRoute",
"Register",
new { controller = "Registration", action = "Register" }
);
Now you can go to your page with an url like:
http://www.yoursite.com/register
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With