ASP.NET Quick Request

How can I turn this /Home/About/ into just /About/ using the rules in the Global.aspx file?

+4
source share
6 answers
  public static void RegisterRoutes(RouteCollection routes) { routes.MapRoute( "About", // Route name "About", // URL new { controller = "Home", action = "About" }); ... } 

@Scott: Thanks. Fixed.

+6
source
  routes.MapRoute( "About", "About", new { controller = "Home", action = "About" } ); 

Just make sure this is the place before the default route handler.

+3
source

Add route:

 routes.MapRoute( "About", "About" new { controller = "Home", action = "About" }); 

Since it is hard-coded, you want to make sure that it is in front of any routes that have placeholders for various parameters.

+1
source

Create a new route to the default route as follows:

 routes.MapRoute("about", "About", new { controller = "YourController", action = "About" }); 
+1
source

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. }); 
0
source

Source: https://habr.com/ru/post/1345154/


All Articles