4

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

5 Answers 5

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

      ...

    }

@Scott: Thanks. Fixed it.

Sign up to request clarification or add additional context in comments.

1 Comment

Putting the / at the beginning of the URL will cause an ArgumentException error
3
   routes.MapRoute(
     "About",
     "About",
     new { controller = "Home", action = "About" }
   );

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

Comments

1

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.

Comments

1

Create a new route before the default route like this:

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.