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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:45:51+00:00 2026-06-18T00:45:51+00:00

I have created one sample internet MVC application. Then created ProductsController with Index view.

  • 0

I have created one sample internet MVC application. Then created ProductsController with Index view.

Then in routing, I mapped product url with products/prodname/id with below routing rules.

routes.MapRoute(
                name: "ProdDef",
                url: "{controller}/{name}/{id}/{action}",
                defaults: new { controller = "Products", action = "Index", id = UrlParameter.Optional, name = UrlParameter.Optional }
            );

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );

But after this, contact page redirects me to home index controller action. ?? why so? Am I missing something and why other actions stopped working after creating only one rule for product.

  • 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-06-18T00:45:52+00:00Added an answer on June 18, 2026 at 12:45 am

    Change your first route to something like

    routes.MapRoute(
        name: "ProdDef",
        url: "products/{name}/{id}/{action}",
        defaults: new { controller = "Products", action = "Index", id = UrlParameter.Optional, name = UrlParameter.Optional }
    );
    

    Otherwise that route will pretty much match anything. Remember that the order of your routes is important, as matching will be attempted in that order.

    Edit :

    The reason for this being that by default the routing handler makes no difference between {controller}/{name} and {controller}/{action}. They’re the same format, only with different parameter names.

    Here’s a breakdown of what happens for say a given URL such as /Home/Index.

    First route will be attempted first, has 4 parameters, 2 of which are optional so no values will be given if they’re not present, leaving you with the following values :

    • controller : Home
    • name : Index
    • action : null but will default to Index as specified
    • id : null

    As you can see both non-optional parameters are filled, therefore the route will match, but will not function as you might have expected. Same thing would happen no matter what the URL is, as long as it has a value for controller and name. Which brings me to my original answer, if you want that first route to match only incoming URLs for products, you need to add something that will allow the routing handler to differentiate it. By replacing {controller} with a hard-coded value of products, now that route will only match incoming URL’s starting with products, leaving anything else to keep going down the route chain as expected.

    Hope that clears it up for you.

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

Sidebar

Related Questions

I have created one sample application , based on UIWebview sample and i added
i am working on one application in which i have created one table view
I have created one service in my grails application. in that service 25 methods
I have created a sample project in asp .net mvc using vs 2010. In
I have created one android project with simple web view. I am trying to
I have created one iPhone application. I am getting Device Token. But I am
I am working on Email client application. I have written one sample program for
Using xlwDotNet, I have created a simple function which returns one number. Sometimes, something
I am a bit confused. I have created a simple form with a one
I have created one UIImageView Here's code capView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:kARROW_CAP_NAME]]; capView.frame

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.