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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:57:08+00:00 2026-05-17T19:57:08+00:00

We are trying to use custom routes in an ASP.NET MVC application to generate

  • 0

We are trying to use custom routes in an ASP.NET MVC application to generate this url: 'http://example.com/Person/unnecessaryinfo-42'. The “unnecessaryinfo” is the name of the id which will make the URL hackable for the user. Below is the code for our route map. This works but my controller action ends up with “unnecesaryinfo-42” in the id parameter. Can I strip the “unnecessaryinfo-” before it reaches the controller action?

routes.MapRoute("person_id", "person/{id}",
    new { controller = "Customer", action = "Details" },
    new { id = @"unnecessaryinfo-\d" });

Edit:

Here’s our latest code:

routes.MapRoute("person_id", "person/{unnecessaryinfo}-{id}",
    new { controller = "Customer", action = "Details" },
    new { id = @"[\d]{1,6}" });

The chapter on Routing from ASP.NET MVC 2 In Action (page 234) discusses avoiding the use of database IDs whenever possible but if you must use them, adding additional information to make the URL readable. This is what we’re trying (unsuccessfully) to do. The database id currently ranges from 1 to 6 digits (and may grow over time).

  • 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-17T19:57:08+00:00Added an answer on May 17, 2026 at 7:57 pm

    Your back and forth on Darin’s answer makes me believe that you probably have another route which is being matched and used instead of this route:

    routes.MapRoute("person_id", "person/{unnecessaryinfo}-{id}",
        new { controller = "Customer", action = "Details" },
        new { id = @"[\d]{1,6}" });
    

    Switching the order in which the routes are added to the RouteCollection should fix the problem. More specific routes should be the first added to the collection. For instance if you also have this route:

    routes.MapRoute("person_login", "person/{id}",
        new { controller = "Customer", action = "Details" });
    

    It should appear after your more specific “person_id” route so your code would look like this:

    routes.MapRoute("person_id", "person/{unnecessaryinfo}-{id}",
        new { controller = "Customer", action = "Details" },
        new { id = @"[\d]{1,6}" });
    
    routes.MapRoute("person_login", "person/{id}",
        new { controller = "Customer", action = "Details" });
    

    The URL your provided 'http://example.com/Person/unnecessaryinfo-42' will match to both routes, but since your more specific route appears first that’s the route that will be used. When a less specific URL is mapped it won’t match the first and therefore the second route will be used.

    That said determining what routes a URL matches can be a bit tricky. Thankfully, there are two pretty good options that assist with route debugging:

    • Phil Haack provides an easy to implement URL Routing Debugger
    • Stephen Walther offers an alternative in Build a Controller to Debug Your Custom Routes

    Stephen’s solution is probably the best for longterm use, but Phil’s is definitely the easier to implement for down and dirty debugging. I’d start with reordering your routes, but if that doesn’t solve the issue use one of the aforementioned debuggers.

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

Sidebar

Related Questions

I'm trying to use Url Routing within my existing ASP.NET WebForms site. Thanks to:
I'm trying to use phantom.js custom buildpack on Heroku ( https://github.com/stomita/heroku-buildpack-phantomjs ) I followed
I am trying to use custom error pages using redirects in IIS7. This is
I'm trying to use a custom event in my WxWidgets C++ application, like described
I'm trying to use a custom sort with a ListView, as described in this
I'm trying to use custom notifications in my Android application using Google's sample from
We are currently developing an application based on NHibernate and ASP.NET MVC and a
I'm trying to use ServiceStack.net so my first service has implemented a Custom CredentialsAuthProvider
I'm trying to use custom meta boxes in wordpress. My goal at the moment
I'm trying to use custom check boxes within Fancybox. They are showing up but

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.