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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:59:44+00:00 2026-05-29T05:59:44+00:00

I am currently writing a news article aspect to an application and I adding

  • 0

I am currently writing a news article aspect to an application and I adding the new route (for the new article) to my RouteTable, which appears to add fine, but the routes are unreachable?

The code I am using is as follows:

var routes = RouteTable.Routes;
using (routes.GetWriteLock())
{
    var url = contentHelper.GetPageUrl(page);
    routes.MapRoute(page.Id.ToString(), url, new { controller = "Cms", action = "Index", id = url }, new[] { "Web.Controllers.CmsController" });
}

The new Url, as I previously said, is added to the RouteTable.Routes but I cant get to the page. After a restart it is picked up by RegisterRoutes in the Global.asax and works fine.

Any light that you can shed on this would be great, as I want to achieve this without forcing an app restart

EDIT

This is the RegisterRoutes from my global.asax

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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

        routes.MapRoute(
                "News", // Route name
                "News/",// URL with parameters
                new { controller = "NewsPage", action = "Index" }, // Parameter defaults
                new[] { "Web.Controllers.NewsController" }
            );

        //register all content pages
        var urls = new ContentPageHelper().GetAllUrls();
        foreach (var url in urls)
        {
            routes.MapRoute(url.Key.ToString(), url.Value, new { controller = "Cms", action = "Index", id = url.Key }, new[] { "Web.Controllers.CmsController" });
        }

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}",// URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );
    }
  • 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-29T05:59:44+00:00Added an answer on May 29, 2026 at 5:59 am

    The issue is that calling RouteTable.MapRoute adds the route to the end of the table. Your default route is generally the last route to be added to the table, but since you are dynamically calling RouteTable.MapRoute after you have already built your route table, the default route is being hit before it reaches your newly added route.

    My solution to this problem was as follows.

        public static void AddContentRoute(this RouteCollection routes, Data.UrlMap map, bool needsLock = false)
        {
            var route = new Route(map.Url, new MvcRouteHandler());
            route.Defaults = new RouteValueDictionary(new
            {
                controller = "Content",
                action = "Display",
                id = map.Id,
                type = map.Type
            });
    
            if (needsLock)
            {
                using (routes.GetWriteLock())
                {
                    routes.Insert(0, route);
                }
            }
            else
            {
                routes.Insert(0, route);
            }
        }
    

    This essentially does what RouteTable.MapRoute does, but inserts the route to the top of the table instead of the end.

    If you have other routes that need to sit at the top of the table you may want to modify this solution.

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

Sidebar

Related Questions

I am currently writing a Comet application which requires me to send chunks of
I am currently writing an application ( App1 ) which retrieves portions of text
I'm currently writing a peer-to-peer chat application to chat around the world, but my
I'm currently writing a TYPO3 extension which is configured with a list of tt_content
I'm writing an application to show some news from a portal. The news are
The application I'm currently writing is using MVVM with the ViewModel-first pattern. I have
I am currently writing a genre classification application as my final year project in
I'm currently writing a small script using pygame, but I don't believe this question
I'm currently writing an application that allows one to store images, and then tag
I'm currently writing a class to handle all database-activity in my application, and so

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.