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 6083171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:22:19+00:00 2026-05-23T11:22:19+00:00

I want to map all CMS pages url to single controller(PageController) and action(Details). How

  • 0

I want to map all CMS pages url to single controller(PageController) and action(Details).

How can I create custom routing to map all these urls?

/teacher
/teacher/kindergarten
/teacher/kindergarten/1
/teacher/primary
/teacher/primary/english
/teacher/primary/language
/teacher/primary/language/chinese
/teacher/primary/math
/teacher/primary/science
/parent
/parent/kindergarten
/parent/primary1-3
/parent/primary4-6
/leader
/leader/kindergarten
/leader/kindergarten/1
  • 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-23T11:22:20+00:00Added an answer on May 23, 2026 at 11:22 am

    If you have these URLs in a database you could map the routes when the application starts up:

      var pages = siteDB.Pages.ToList();
      string pagePath = "";
      foreach (var page in pages)
      {
        routeVals = new RouteValueDictionary();
        constraints = new RouteValueDictionary();
    
        routeVals.Add("controller", "page");
        routeVals.Add("action", "details");
    
        constraints.Add("path", "[a-zA-Z0-9\\-]*");
    
        // any child pages? must add these routes before their parent pages.
        var childPages = siteDB.Pages.Where(p => p.ParentPageId == page.PageId).ToList();
        foreach (var childPage in childPages)
        {
          pagePath = BuildPath(childPage);
          RouteTable.Routes.Add(new Route(pagePath, new MvcRouteHandler())
          {
            Defaults = routeVals,
            Constraints = constraints,
            DataTokens =
                new RouteValueDictionary {
                { "pageid", childPage.PageId },
                { "path", pagePath }
              }
          });
    
          // Any further child pages? (Only 3 levels supported)
            var childSubPages = siteDB.Pages.Where(p => p.ParentPageId == childPage.PageId).ToList();
            foreach (var childSubPage in childSubPages)
            {
                pagePath = BuildPath(childSubPage);
                RouteTable.Routes.Add(new Route(pagePath, new MvcRouteHandler())
                {
                    Defaults = routeVals,
                    Constraints = constraints,
                    DataTokens =
                        new RouteValueDictionary {
                    { "pageid", childSubPage.PageId },
                    { "path", pagePath }
                  }
                });
            }
        }
    

    This code takes the pages from a database where they are linked by parent id.

    Here’s the BuildPath function which generates a full path to each page:

    public static string BuildPath(Page page)
    {
      if (page.ParentPageId == 1)
      {
        return page.PageKey;
      }
      else
      {
        SiteDataEntities siteDB = new SiteDataEntities();
        string path = page.PageKey;
        Page parent = siteDB.Pages.Find(page.ParentPageId);
        while (parent != null)
        {
          path = parent.PageKey + "/" + path;
          parent = siteDB.Pages.Find(parent.ParentPageId);
          if (parent.PageKey == "home") break;
        }
        return path;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Example: I want to create one AutoResponse rule that will map all calls to
I want to map all properties that match between two class instances. public class
I am using <url-pattern>/*</url-pattern> to map all the requests to one sevlet,where i do
I want to map all partitions from all drives in Windows (the ones who
I want to map elements of an array such that all elements of the
I know this removes duplicates : @email.distributions.map(&:zip_code) & CardSignup.all.map(&:zip_code) But I want to do
I have two routes: map.all_devices '/all_devices', :controller => 'all_devices', :action => 'initialize_devices' map.show_user_date_select '/all_devices',
Hi All / very new to Auto-Mapper. i can map one to one objects
How do i map multiple url's to the same action in asp.net mvc I
I want to map a INI file as a python object. So if 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.