Reputation: 28853
How can I turn this /Home/About/
into just /About/
using the rules in the Global.aspx file?
Upvotes: 4
Views: 90
Reputation: 2385
I used this:
routes.MapRoute(
"HomeActions",
"{action}",
new
{
controller = "Home",
action = "Index" // I technically don't think this is required.
},
new // The second object are route constraints
{
action = "Index|FAQ|ContactUs|Examples|Materials|Members" // <-- various actions on my home controller. Any regex works here.
});
Upvotes: 0
Reputation: 1911
this will give you the explanation too :) http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
Upvotes: 1
Reputation: 9463
Create a new route before the default route like this:
routes.MapRoute("about", "About", new { controller = "YourController", action = "About" });
Upvotes: 1
Reputation: 47766
Add a route:
routes.MapRoute(
"About",
"About"
new { controller = "Home", action = "About" });
Since it is hardcoded, you want to make sure it is before any routes that have placeholders for the various params.
Upvotes: 1
Reputation: 2249
routes.MapRoute(
"About",
"About",
new { controller = "Home", action = "About" }
);
Just make sure it is place before the default route handler.
Upvotes: 3
Reputation: 21898
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
"About", // Route name
"About", // URL
new { controller = "Home", action = "About" });
...
}
@Scott: Thanks. Fixed it.
Upvotes: 6