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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:38:48+00:00 2026-05-25T21:38:48+00:00

In ASP.NET 2, how do I create a route that allows lookup of an

  • 0

In ASP.NET 2, how do I create a route that allows lookup of an object (eg Product) by a string id (eg ProductCode)? The route for looking up the same object by it’s integer id (eg ProductId) is automatic, so I don’t actually know how it works.

The automatic route by id is:

/Product/1

How do I also create a 2nd route that uses a string id?

/Product/red-widget

And how do I do it so that both routes are available?

  • 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-25T21:38:49+00:00Added an answer on May 25, 2026 at 9:38 pm

    You should take a look at using a route constraint to do this. See http://www.asp.net/mvc/tutorials/creating-a-route-constraint-cs

    routes.MapRoute(
        "Product",
        "Product/{productId}",
        new {controller="Product", action="DetailsByName"},
        new {productId = @"\w+" }
     );
    

    In the above, the constraint regex “\w+” should limit to routes that match only “word” characters (take a look at regex docs for more details on patterns used here).

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

Sidebar

Related Questions

ASP.Net 3.5 I want to create a user control that contains the ListView and
I have ASP.NET 4 project (not MVC). I need to create url route based
I have an Asp.Net Mvc website that has a listing controller. The route looks
In my asp.net MVC 3 project I would like to create a contact that's
I'm trying to accomplish the following in ASP.Net: Create a WPF Canvas control Spin
i am trying to use the jquery form wizard with asp.net to create a
I just wanna ask if there's a way in C#/ASP.NET to create 'dynamic' tables/fields
I intend to create asp.net pages using Visual Studio 2008. Preferably, the pages should
I'm trying to create ASP.NET MVC Application with Entity Framework, which has One to
Is it possible to create ASP.NET MVC applications in VS 2010? What should I

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.