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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:28:14+00:00 2026-05-16T00:28:14+00:00

I am working with ASP.NET MVC 2 and would like to optimize my routing.

  • 0

I am working with ASP.NET MVC 2 and would like to optimize my routing. The desired result is as follows:

http://www.url.com/Sites/
http://www.url.com/Sites/Search/NY001
http://www.url.com/Sites/NY001
http://www.url.com/Sites/NY001/Photos

The problem with this scenario is that I want to treat the URL bits differently depending on their content, in a sense. As one can imagine, “NY001” is the identifier for a specific site, not for an action that lives in the Sites controller. My current solution is to define a special route map for the site-specific URLs and to specify each action in the Sites controller separately before that.

// currently in place, works
routes.MapRoute("SiteList", "Sites", new { controller = "Sites", action = "Index" });
routes.MapRoute("SiteSearch", "Sites/Search/{searchString}", new { controller = "Sites", action = "Index", searchString = "" });
routes.MapRoute("SiteNotFound", "Sites/NotFound", new { controller = "Sites", action = "NotFound" });
// and so on...

routes.MapRoute("Site", "Sites/{siteId}/{action}", new { controller = "Sites", action = "Index", siteId = "" });

As this is one of the central components of my web application, these actions are growing daily and the list is getting a bit unwieldy. I would love to be able to distill the long list of action-specific routes to a single declaration, similar to this:

routes.MapRoute("Sites", "Sites/{action}/{id}", new { controller = "Sites", action = "Index", id = UrlParameter.Optional });

The problem is that the routing framework has no way of differentiating between this new route and the site-specific one in the above example; therefore, both are matches. Am I stuck with declaring each action separately? Should I consider using a regular expression to differentiate based on the URLs’ content?

Thanks in advance and I apologize in advance if this question has already been asked in a different form.

  • 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-16T00:28:16+00:00Added an answer on May 16, 2026 at 12:28 am

    Not sure what exactly you want to accomplish. Of course you can’t really map URLs with different signatures with one route, but you can reduce the list like this:

    routes.MapRoute("Site", "Sites/{siteId}/{action}", new { controller = "Sites", action = "Index" }, new { action = "(?:Index|Photos|News)", siteId = @"[A-Z0-9]+" });
    

    for urls:

    http://www.url.com/Sites/NY001
    http://www.url.com/Sites/NY001/Photos
    http://www.url.com/Sites/NY001/News
    

    This route will only map to actions Index, Photos, News (and whatever else you put in that reg. expression).

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

Sidebar

Related Questions

I'm working with ASP.Net MVC and I would like to make a web site
I'm currently working on an asp.net-mvc content management system. It would be incredibly useful
I'm working on an editor page for a project in ASP.NET MVC. I would
I have an existing ASP .NET MVC application and I would like to ignore
I'm trying out ASP.NET MVC Framework and would like to create an ajax helper
I'm currently learning ASP.NET MVC and using Nhibernate. I would like to use Cascading
I am currently working on an ASP.NET MVC2 application and would just like to
After working with ASP.Net MVC, it has me thinking about Rails. I worked with
I've been working with ASP.NET MVC for the last few weeks, learning as I
I've been working with asp.net MVC and am still not very good at it.

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.