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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:07:04+00:00 2026-05-13T19:07:04+00:00

can I have domain.com/action/id as well as domain.com/controller/action? how would I register these in

  • 0

can I have domain.com/action/id as well as domain.com/controller/action?

how would I register these in the route-table?

  • 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-13T19:07:04+00:00Added an answer on May 13, 2026 at 7:07 pm

    Is ID always guaranteed to be a number? If yes, then you could use RouteConstraints:

    routes.MapRoute("ActionIDRoute",
                   "{action}/{id}",
                   new { controller = "SomeController" },
                   new {id= new IDConstraint()});
    routes.MapRoute("ControllerActionRoute",
                    "{controller}/{action}",
                    new {}); // not sure about this last line
    

    The IDConstraint class looks like this:

    public class IDConstraint : IRouteConstraint
    {
        public bool Match(HttpContextBase httpContext, Route route,
                          string parameterName, RouteValueDictionary values,
                          RouteDirection routeDirection)
        {
            var value = values[parameterName] as string;
            int ID;
            return int.TryParse(value,out ID);
        }
    }
    

    Basically what is happening is that you have two identical routes here – two parameters, so it’s ambigous. Route Constraints are applied to parameters to see if they match.

    So:

    1. You call http://localhost/SomeController/SomeAction
    2. It will hit the ActionIDRoute, as this has two placeholders
    3. As there is a constraint on the id parameter (SomeAction), ASP.net MVC will call the Match() function
    4. As int.TryParse fails on SomeAction, the route is discarded
    5. The next route that matches is the ControllerActionRoute
    6. As this matches and there are no constraints on it, this will be taken

    If ID is not guaranteed to be a number, then you have the problem to resolve the ambiguity. The only solution I am aware of is hardcoding the routes where {action}/{id} applies, which may not be possible always.

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

Sidebar

Related Questions

I hate the codeigniter custom urls where it's: domain.com/controller/action/id How can I have it
In google app engine can I have www.domain.com point to version X of my
I can't get MediaWiki to work on Nginx. I have it in my /var/www/domain.com/htdocs/wiki
I have 2 domain: domain1.com and domain2.com how can i know what is the
I have an action email in my controller of application running on www.example.com and
I'm trying to get the source of an internal domain page can have it
I have datagrid whichs items source is domainDataSource. How i can refresh Domain data
I'm trying to create a Route in Cakephp that can have anything as a
I have a controller in Ruby on Rails and I would like to do
I have a default routing so if I go to www.domain.com/app/ it's, for example,

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.