How can I turn this /Home/About/ into just /About/ using the rules in the Global.aspx file?
/Home/About/
/About/
public static void RegisterRoutes(RouteCollection routes) { routes.MapRoute( "About", // Route name "About", // URL new { controller = "Home", action = "About" }); ... }
@Scott: Thanks. Fixed.
routes.MapRoute( "About", "About", new { controller = "Home", action = "About" } );
Just make sure this is the place before the default route handler.
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.
Create a new route to the default route as follows:
routes.MapRoute("about", "About", new { controller = "YourController", action = "About" });
this will also give you an explanation :) http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
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. });
Source: https://habr.com/ru/post/1345154/More articles:haml with rdiscount markdown claims not found - ruby-on-railsAJAX security question, please contact - jqueryAny code examples for creating a Rails 3 controller for a WebDAV server? - ruby-on-rails-3scoped_lock not working in file? - boostRails 3.1 application with built-in webdav and authentication? - ruby-on-railsThe Dreaded Evercookie and CakePHP - javascriptHow to set the order of Zend form elements and avoid duplicates - zend-frameworkTextBox in MessageBox on Windows Phone 7 - windows-phone-7Is there a command line argument in Chrome to launch developer tools at startup? - javascriptDo not request input - javaAll Articles