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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:38:32+00:00 2026-06-08T18:38:32+00:00

In my application, I have a Area(XYZ) having a controller(XYZController) and bunch of other

  • 0

In my application, I have a Area(XYZ) having a controller(XYZController) and bunch of other Controllers inside the area. The XYZController has general actions like Index,View,Create,Edit etc. The More specific actions related to some particular functionality are arranged accordingly in the corresponding controller.

To avoid URL having structure like: app/XYZ(area)/XYZ(Controller)/Create, I added a routing as follows to the Area route register file.

context.MapRoute(
                  "XYZ_AreaDefaultControllerActions",
                  "XYZ/{action}/{id}",
                  new { controller = "XYZ", id = UrlParameter.Optional },
                  new { controller = "XYZ" },
                  new string[] { "App.Web.Areas.XYZ.Controllers.*" } 
              );

context.MapRoute(
                "XYZ_default",
                "XYZ/{controller}/{action}/{id}",
                new { controller = "XYZ", action = "Index", id = UrlParameter.Optional}
        );

This mapping routes the url: app/XYZ/Create to area = XYZ, Controller = XYZ and Action = Create which is correct and is what I want to do but messes up routing of some other Post actions.

Consider this, I have another controller called Notes controller which has some Post actions.

A action with url as /app/XYZ/Notes/List/id is routed correctly when the request is a HTTP Get and the output from route debugger shows that the 2nd route definition matches and the first one doesn’t.

When i do a post to the same controller with an action AddNote with url /App/XYZ/Notes/AddNote the 1st route definition matches according to the route debugger and as a result the action is not found as it takes Controller = XYZ, Action = Notes, Id = AddNote.
Here is the output from the route debugger:

Matches | Url | Defaults | Constraints

  1. True | XYZ/{action}/{id} | controller = XYZ, id = | controller = XYZ

  2. True | XYZ/{controller}/{action}/{id} | controller = XYZ, action = Index, id = |(null)

The problem is that seems like the contraints of the first route are not restricting it enough in the case of Post while in Get it applied the constraint.

Any suggestions what is going wrong here?

  • 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-08T18:38:33+00:00Added an answer on June 8, 2026 at 6:38 pm

    If your XYZController does not have any POST actions, you could add a constraint like this to prevent POST requests from matching your first route:

    context.MapRoute("XYZ_AreaDefaultControllerActions",
        "XYZ/{action}/{id}",
        new { controller = "XYZ", id = UrlParameter.Optional },
        new { controller = "XYZ", httpMethod = new HttpMethodConstraint("GET") },
        new string[] { "App.Web.Areas.XYZ.Controllers.*" }
    );
    

    Update

    Since you have post actions in the XYZController, like you mentioned, the above route constraint won’t work for you.

    The problem here is that you have a controller with the same name as your area. This is why MVC is matching the first route to your notes controller POST action, because it is just trying to match the tokens up based on the incoming URL:

    • /XYZ – this matches the first segment of your first route literally
    • /Notes – this gets filled into your {action} segment
    • /AddNote – this gets filled into your {id} segment

    Given your first route, a { controller = "XYZ" } constraint does not make any difference because MVC is trying to route an inbound URL to a controller + action + args. MVC does not have any idea what controller it is coming from, it is trying to match what controller and action will handle the URL request.

    One solution is to add action constraints to your first route, but this will only work if your action names in XYZController don’t match any of the POST action names in your notes controller:

    new { controller = "XYZ", action = "XYZAction1|XYZAction2|XYZActionN" },
    

    For incoming routes, this will only match the first route when the action is one of the pipe-separated names in the constraint.

    Another option would be to constrain your {id} route segment using a regex. If your id’s are strings, this might not be an option. However if your ids are always numbers, you can constrain the first route to only match route segments to the {id} token when they are numeric. This way, “AddNote” would not match the {id} segment of your first route because it is not numeric:

    new { controller = "XYZ", id = @"\d+" },
    

    To answer your second comment, the reason this works with GET is because your second route has an additional route segment. GETS with id’s don’t match the first route because they have 4 tokens, not 3.

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

Sidebar

Related Questions

I have an application that has an area that is supposed to behave somewhat
In my application I have controller named Snippets both in default area (in application
In my mvc application I have Admin area and have default controllers outside area.
I'm making a web application and would like to have a secure area where
In my application I have large area (≈5000x5000pts) and I must allow user to
I have some text area field in my grails application. I got the following
I have an ASP.NET MVC 3 application (in IIS 7.5) with a portable area.
I have a client apllication that run in very restricted area - it has
In my application I have an area call Mobile. In this area I have
In my application I have an area in the main window that at any

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.