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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:41:49+00:00 2026-06-15T05:41:49+00:00

I have the default Route in Global.asax: RouteTable.Routes.MapHttpRoute( name: DefaultApi, routeTemplate: api/{controller}/{id}, defaults: new

  • 0

I have the default Route in Global.asax:

 RouteTable.Routes.MapHttpRoute(
         name: "DefaultApi",
         routeTemplate: "api/{controller}/{id}",
         defaults: new { id = System.Web.Http.RouteParameter.Optional }
         );

I wanted to be able to target a specific function, so I created another route:

RouteTable.Routes.MapHttpRoute(
         name: "WithActionApi",
         routeTemplate: "api/{controller}/{action}/{id}",
         defaults: new { id = System.Web.Http.RouteParameter.Optional }
         );

So, in my controller, I have:

    public string Get(int id)
    {
        return "object of id id";
    }        

    [HttpGet]
    public IEnumerable<string> ByCategoryId(int id)
    {
        return new string[] { "byCategory1", "byCategory2" };
    }

Calling .../api/records/bycategoryid/5 will give me what I want.
However, calling .../api/records/1 will give me the error

Multiple actions were found that match the request: …

I understand why that is – the routes just define what URLs are valid, but when it comes to function matching, both Get(int id) and ByCategoryId(int id) match api/{controller}/{id}, which is what confuses the framework.

What do I need to do to get the default API route to work again, and keep the one with {action}? I thought of creating a different controller named RecordByCategoryIdController to match the default API route, for which I would request .../api/recordbycategoryid/5. However, I find that to be a “dirty” (thus unsatisfactory) solution. I’ve looked for answers on this and no tutorial out there on using a route with {action} even mentions this issue.

  • 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-15T05:41:50+00:00Added an answer on June 15, 2026 at 5:41 am

    The route engine uses the same sequence as you add rules into it. Once it gets the first matched rule, it will stop checking other rules and take this to search for controller and action.

    So, you should:

    1. Put your specific rules ahead of your general rules(like default), which means use RouteTable.Routes.MapHttpRoute to map “WithActionApi” first, then “DefaultApi”.

    2. Remove the defaults: new { id = System.Web.Http.RouteParameter.Optional } parameter of your “WithActionApi” rule because once id is optional, url like “/api/{part1}/{part2}” will never goes into “DefaultApi”.

    3. Add an named action to your “DefaultApi” to tell the route engine which action to enter. Otherwise once you have more than one actions in your controller, the engine won’t know which one to use and throws “Multiple actions were found that match the request: …”. Then to make it matches your Get method, use an ActionNameAttribute.

    So your route should like this:

    // Map this rule first
    RouteTable.Routes.MapRoute(
         "WithActionApi",
         "api/{controller}/{action}/{id}"
     );
    
    RouteTable.Routes.MapRoute(
        "DefaultApi",
        "api/{controller}/{id}",
        new { action="DefaultAction", id = System.Web.Http.RouteParameter.Optional }
    );
    

    And your controller:

    [ActionName("DefaultAction")] //Map Action and you can name your method with any text
    public string Get(int id)
    {
        return "object of id id";
    }        
    
    [HttpGet]
    public IEnumerable<string> ByCategoryId(int id)
    {
        return new string[] { "byCategory1", "byCategory2" };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Global.asax route values routes.MapRoute( Default, // Route name {controller}/{action}/{id}, // URL with parameters new
I have this route values inside Global.asax routes.MapRoute( Default, // Route name {controller}/{action}/{id}, //
I have two MapRoute in global asax.` routes.MapRoute( AutoGeneratedURLHandler, // Route name {modulepath}/{controller}/{action}/{id}, //
I have the following route: routes.MapRoute( Default, // Route name {controller}/{action}/{id}, // URL with
I have a rule in my Global.asax like so: RouteTable.Routes.MapPageRoute(defaultRoute, {*value}, ~/default.aspx) Essentially, any
In my global.asax.vb I have a rule like so: RouteTable.Routes.MapPageRoute(defaultRoute, {*value}, ~/default.aspx) So, if
i defined two routes in global.asax like below context.MapRoute(HomeRedirect, , new { controller =
In my MVC application I have a default route defined: routes.MapRoute( Default, // Route
I would like to change my default route values. Right now, I have: routes.MapRoute(
I have the following URl: http://localhost:12981/BaseEvent/EventOverview/12?type=Film This is route: routes.MapRoute( Default, // Route name

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.