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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:20:21+00:00 2026-05-19T11:20:21+00:00

Given this route: routes.MapRoute(home, {action}/{id}, new { controller = home, action = index, id

  • 0

Given this route:

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

…and this action:

public ActionResult Hi(string id) {
   return Content("hello, id: " + id);
}

Question #1
What is the response for:

GET http://localhost:2247/hi/7?id=55 HTTP/1.1

Question #2
What is the response for:

POST http://localhost:2247/hi/7?id=55 HTTP/1.1
Content-Length: 4
Content-Type: application/x-www-form-urlencoded

id=3

I believe this is a bug and the route value should always have precedence, since the URL is what identifies a resource. If you write a POST, PUT or DELETE action you expect the id coming from the URL, not from the body of the request. This could cause changes to a different resource, and can be exploited by malicious users.


After doing some research found that the issue is the default ValueProviderFactory registration order, where FormValueProviderFactory comes before RouteDataValueProviderFactory. Instead of messing with the order I created a CustomModelBinderAttribute:

[AttributeUsage(AttributeTargets.Parameter)]
public sealed class FromRouteAttribute : CustomModelBinderAttribute, IModelBinder {

   public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {

      bindingContext.ValueProvider = new RouteDataValueProvider(controllerContext);

      return ModelBinders.Binders.DefaultBinder.BindModel(controllerContext, bindingContext);
   }

   public override IModelBinder GetBinder() {
      return this;
   }
}

…which you can use like this:

public ActionResult Hi([FromRoute]string id) {
   return Content("hello, id: " + id);
}
  • 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-19T11:20:21+00:00Added an answer on May 19, 2026 at 11:20 am

    In ASP.NET MVC 3 RC2:

    • GET: Response: hello, id: 7
    • POST: Response: hello, id: 3

    And here’s the test view:

    <a href="/hi/7?id=55">GET</a>
    <form action="/hi/7?id=55" method="POST">
        <input type="hidden" name="id" value="3" />
        <input type="submit" value="POST" />
    </form>
    

    So here is the evaluation precedence order:

    1. POST body parameter
    2. Route
    3. Query string parameter

    And by the way the exact same result is obtained with ASP.NET MVC 2.0.

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

Sidebar

Related Questions

Given the following routes: routes.MapRoute(name: CityHomePage1, url: {city}-{state}, defaults: new { controller = Home,
I have this route routes.MapRoute( ViewGames, // Route name psp/{controller}/{action}, // URL with parameters
I define routes in my global.asax, like this: routes.MapRoute( Default, {controller}/{action}/{id}, new { controller
Given the following route: context.MapRoute(null, widgets, new { controller = Widgets, action = Add
In the MVC default route routes.MapRoute( Default, // Route name {controller}/{action}/{id}, // URL with
Take the following controller action public ActionResult NextBySURNAME(int id, string data) { //code to
routes .Add (Detail, new Route ({maincategory}/{category}, new RouteValueDictionary (new { controller = Category, action
Im trying to do something like this: routes.MapRoute(Product, {product}/{id}, new { action = Product,
Can anyone explain why this code with the given routes returns the first route?
Given this code: var arrayStrings = new string[1000]; Parallel.ForEach<string>(arrayStrings, someString => { DoSomething(someString); });

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.