Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3633704
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:41:11+00:00 2026-05-19T00:41:11+00:00

Having some trouble with some routes. I don’t fully understand the MVC routing system

  • 0

Having some trouble with some routes. I don’t fully understand the MVC routing system so bear with me.

I’ve got two controllers, Products and Home (with more to come!).

I want to have the views within the Home controller accessible without having to type Home in the url. Essentially I want to turn http://www.example.com/home/about into http://www.example.com/about, however I still want to preserve the http://www.example.com/products.

Here’s what I have so far.

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

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "home", action = "index", id = UrlParameter.Optional }
);

Now depending on which one is first I can get either one or the other to work, but not both.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:41:12+00:00Added an answer on May 19, 2026 at 12:41 am

    I think what you might be looking for is something that that the author of the code below has termed a Root Controller. I have used this myself on a couple sites, and it really makes for nice URLS, while not requiring you to create more controllers that you’d like to, or end up with duplicate URLs.

    This route is in Global.asax:

            // Root Controller Based on: ASP.NET MVC root url’s with generic routing Posted by William on Sep 19, 2009
            //  http://www.wduffy.co.uk/blog/aspnet-mvc-root-urls-with-generic-routing/
            routes.MapRoute(
                "Root",
                "{action}/{id}",
                new { controller = "Root", action = "Index", id = UrlParameter.Optional },
                new { IsRootAction = new IsRootActionConstraint() }  // Route Constraint
            );
    

    With this defined elsewhere:

        public class IsRootActionConstraint : IRouteConstraint
        {
            private Dictionary<string, Type> _controllers;
    
            public IsRootActionConstraint()
            {
                _controllers = Assembly
                                    .GetCallingAssembly()
                                    .GetTypes()
                                    .Where(type => type.IsSubclassOf(typeof(Controller)))
                                    .ToDictionary(key => key.Name.Replace("Controller", ""));
            }
    
            #region IRouteConstraint Members
    
            public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
            {
                string action=values["action"] as string;
                // Check for controller names
                return !_controllers.Keys.Contains(action);
            }
    
            #endregion
        }
    

    The RootActionContraint alows you to still have other routes, and prevents the RootController actions from hiding any controllers.

    You also need to create a controller called Root. This is not a complete implementation. Read the original article here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble with ASP.NET MVC Beta, and the idea of making routes,
Im having some trouble with joining two tables. This is what my two tables
I am having some trouble when I use ASP .Net 4's URL Routing feature
I'm having some trouble getting routes to match. I am using base-32 encoded int's
Having some trouble with some nested resources routing. What I'm trying to do is
I'm having a bit of trouble on some of my controllers. Some of them
Having some trouble with what should be a very simple scenario. For example purposes,
Hey having some trouble trying to maintain transparency on a png when i create
Basically having some trouble with using Hover to hide or show an item. The
Been having some trouble implementing a single-column index in LaTeX. I've been employing the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.