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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:01:35+00:00 2026-05-26T14:01:35+00:00

I realize the concept of having routing defined and executed in a specific order

  • 0

I realize the concept of having routing defined and executed in a specific order but I have the following routes defined:

routes.MapRoute(
            "Image",                                        
            "Image/{action}/{width}/{height}/{file}",       
            new { controller = "Image", action = "Thumbnail", width = 250, height = 250 }
        );

routes.MapRoute(
           "GetCampaignsByCampaignType",
           "Endorsement/GetCampaignsByCampaignType/{campaignType}",
           new { controller = "Endorsement", action = "GetCampaignsByCampaignType" }
        );

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

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

routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
        );

routes.MapRoute(
            "Campaign",
            "{campaignUrlName}",
            new { controller = "Endorsement", action = "GetCampaign" }
        );

The question has to do with the bottom 2 routes. I have campaigns like /Summer, /Winter, /Some-other-name where I have hundreds of these and would like not to hard-code them in. I also have other routes that I want to be hit like /Campaign/Account, /Help/Me/Please (where there are more than one segment /1/2 or /1/2/3)

What is the proper order or definition to allow me to have /1 go to the last route defined above and /1/2 or /1/2/3 go the default {controller}/{action}/{id}

Currently, both scenarios go to the default route {controller}/{action}/{id} including /1. If I reverse them, then /1 works but /1/2 or /1/2/3 does not go to the default routing.

Any help is appreciated.

  • 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-26T14:01:36+00:00Added an answer on May 26, 2026 at 2:01 pm

    Found a solution via regex:

     routes.MapRoute(
                "Default",
                "{controller}/{action}/{id}",
                new { controller = "Home", id = UrlParameter.Optional },
                new { action = @"\w*" }
            );
    
            routes.MapRoute(
                "Campaign",
                "{campaignUrlName}",
                new { controller = "Endorsement", action = "GetCampaign" },
                new { campaignUrlName = @"^([a-zA-Z])[a-zA-Z_-]*[\w_-]*[\S]$|^([a-zA-Z])[0-9_-]*[\S]$|^[a-zA-Z]*[\S]$" }
            );
    

    This way action is required which defaults to two segments /1/2 (perfect) and never catches any single segment urls and the last route gets hit after it passes all others and simply makes sure that it contains proper characters.

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

Sidebar

Related Questions

I realize this is syntactically bad but I figure it somewhat explains what I'm
I realize that a SO user has formerly asked this question but it was
I realize there are similar questions on this topic, but I still cannot find
I realize this is more of a hardware question, but this is also very
I really love the concept of RedBeanPHP. Under development one doesn't have to worry
I have gone through Django's basic Poll tutorial, and I realize that I can
Sorry but this is a concept that I never realized and I never used
This is probably a stupid question, but I'm really struggling with this concept. I'm
Sorry for the many-part question, but I am having a difficult time understanding the
Before anyone says try searching, I have - I realize this is probably a

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.