I have one site and the controller is a name of the user like /John/NewPage, same thing for Mary.
How can I do this without having to create a controller for each new user?
Thks
I have one site and the controller is a name of the user like /John/NewPage, same thing for Mary.
How can I do this without having to create a controller for each new user?
Thks
You could do something like this. Define a controller named something like "UserController" then use custom routes so that it isn't necessary to have "UserController" in the URL:
context.MapRoute(
"User_Route", // Route name
"{userName}/{action}", // URL with parameters
new {
controller = "UserController",
action = "NewPage"
} // Parameter defaults
);
With that setup, the "/Mary/NewPage" URL would call UserController.NewPage("Mary"), "/John/EditPage" would call UserController.EditPage("John"), and just "/Jane" would call UserController.NewPage("Jane").
You would also need to define routes for different controllers above that route so they would get called first. For example:
context.MapRoute(
"SomeOther_Route", // Route name
"SomeOtherController/{action}/{id}", // URL with parameters
new {
controller = "SomeOtherController"
} // Parameter defaults
);
The above URLs will still work, but now this URL "/SomeOtherController/DefinedAction/12" will call something like SomeOtherController.DefinedAction(12).