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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:59:45+00:00 2026-05-18T21:59:45+00:00

I’m working on a Legacy ASP.NET system. I say legacy because there are NO

  • 0

I’m working on a Legacy ASP.NET system. I say legacy because there are NO tests around 90% of the system. I’m trying to fix the routes in this project and I’m running into a issue I wish to solve with generic routes.

I have the following routes:

        routes.MapRoute(
             "DefaultWithPdn",
             "{controller}/{action}/{pdn}",
             new { controller = "", action = "Index", pdn = "" },
             null
         );

        routes.MapRoute(
           "DefaultWithClientId",
           "{controller}/{action}/{clientId}",
           new { controller = "", action = "index", clientid = "" },
           null
       );

The problem is that the first route is catching all of the traffic for what I need to be routed to the second route. The route is generic (no controller is defined in the constraint in either route definition) because multiple controllers throughout the entire app share this same premise (sometimes we need a “pdn” sometimes we need a “clientId”).

How can I map these generic routes so that they go to the proper controller and action, yet not have one be too greedy? Or can I at all? Are these routes too generic (which is what I’m starting to believe is the case).

My only option at this point (AFAIK) is one of the following:

In the contraints, apply a regex to match the action values like: (foo|bar|biz|bang) and the same for the controller: (home|customer|products) for each controller. However, this has a problem in the fact that I may need to do this:

~/Foo/Home/123 // Should map to “DefaultwithPdn”

~/Foo/Home/abc // Should map to “DefaultWithClientId”

Which means that if the Foo Controller has an action that takes a pdn and another action that takes a clientId (which happens all the time in this app), the wrong route is chosen.

To hardcode these contstraints into each possible controller/action combo seems like a lot of duplication to me and I have the feeling I’ve been looking at the problem for too long so I need another pair of eyes to help out.

Can I have generic routes to handle this scenario? Or do I need to have custom routes for each controller with constraints applied to the actions on those routes?

Thanks

  • 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-18T21:59:46+00:00Added an answer on May 18, 2026 at 9:59 pm

    Add constraints to your routes by removing the null and replacing it with the constraint needed for that route:

    For PDN, use a regular expression for digits:

       routes.MapRoute(
             "DefaultWithPdn",
             "{controller}/{action}/{pdn}",
             new { controller = "", action = "Index", pdn = "" },
             new { pdn = @"\d+" } 
         );
    

    For ClientID, use a regular expression for all characters:

        routes.MapRoute(
           "DefaultWithClientId",
           "{controller}/{action}/{clientid}",
           new { controller = "", action = "index", clientid = "" },
           new { clientid = @"[A-Za-z]+" }
       );
    

    Since I don’t keep the minutia of regular expression stuff in my head, I generally use a cheat sheet.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Let's say I'm outputting a post title and in our database, it's Hello Y’all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,

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.