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

  • Home
  • SEARCH
  • 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 8472073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:58:01+00:00 2026-06-10T16:58:01+00:00

I have the following routes set up: context.MapRoute( content_article, A{rk}/{title}, new { controller =

  • 0

I have the following routes set up:

        context.MapRoute(
            "content_article",
            "A{rk}/{title}",
            new { controller = "Server", action = "Article" },
            new { rk = @"^[\dA-Z]{3}$" }
        );

        context.MapRoute(
            "content_contentBlock",
            "C{rk}/{title}",
            new { controller = "Server", action = "ContentBlock" },
            new { rk = @"^[\dA-Z]{3}$" }
        );

        context.MapRoute(
            "content_favoritesList",
            "F{rk}/{title}",
            new { controller = "Server", action = "FavoritesList" },
            new { rk = @"^[\dA-Z]{3}$" }
        );

Is there a way that I could combine:

"A{rk}/{title}",
"C{rk}/{title}",
"F{rk}/{title}",

into one single route with an action of Index that’s taken if the URL starts with an A, C or F?

  • 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-06-10T16:58:03+00:00Added an answer on June 10, 2026 at 4:58 pm

    So if I understand correctly you want just one route to cover all three and to point to Index action? If that’s the question than the answer is

    Sure you can

    You just have to change your regular expression a little to this route definition:

    context.MapRoute(
        "content",
        "{lrk}/{title}",
        new { controller = "Server", action = "Index" },
        new { lrk = @"^[ACF][0-9A-Z]{3}$" }
    );
    

    And that’s it. Parsing of the first letter out is then done by Index action that would likely (and hopefully) execute an appropriate separate method.

    public ActionResult Index(string lrk)
    {
        if (string.IsNullOrEmpty(lrk))
        {
            throw new ArgumentException("lrk")
        }
        char first = lrk[0];
        switch(first)
        {
            case 'A':
                return GetArticle(lrk.Substring(1));
            case 'C':
                return GetContent(lrk.Substring(1));
            case 'F':
                return GetFavorites(lrk.Substring(1));
            default:
                return View();
        }
    }
    
    private ActionResult GetArticle(string rk)
    {
        ...
    }
    
    // and other couple
    

    As you can see the three methods have the same signature as if they were controller actions, but they’re not, since they’re private. You can either set them as private or decorathe them with NonActionAttribute so they can’t get picked up by your default route, that you likely have as well…

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

Sidebar

Related Questions

I have the following route set up: context.MapRoute( MyAccount_default, MyAccount/{controller}/{action}/{id}, new { action =
I currently have the following route set up: context.MapRoute(Root, , new { controller =
I have the following route: routes.MapRoute( Default, // Route name {controller}/{action}/{id}, // URL with
I have this set of routes: routes.MapRoute( IssueType, issue/{type}, new { controller = Issue,
I have the following in my Global.asax.cs routes.MapRoute( Arrival, {partnerID}, new { controller =
I have the following two routes in my app: Router::connect('/posts/:id', array('controller' => 'posts', 'action'
I have the following route's defined: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute({resource}.axd/{*pathInfo}); routes.MapRoute(
I have the following URl: http://localhost:12981/BaseEvent/EventOverview/12?type=Film This is route: routes.MapRoute( Default, // Route name
I have the following route: {language}/{controller}.mvc/{action}/{id} Once a user has choosen the language it
I have the following in my routes.rb: resources :users do resources :decisions end /users/new

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.