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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:20:02+00:00 2026-06-17T17:20:02+00:00

It seems there is a built-in default logic for Web API to use the

  • 0

It seems there is a built-in default logic for Web API to use the HTTP Verb as the action name if no action was supplied in the URL. For example, I have this route:

        config.Routes.MapHttpRoute(
            name: "DefaultApiController",
            routeTemplate: "api/{controller}"
        );

And here are my actions:

    public IEnumerable<Conference> Get()
    {
        ...
    }

    [ActionName("current")]
    public IEnumerable<Conference> GetCurrent()
    {
        ...
    }

When I go to ~/Conferences with a GET verb, it will take you to the “Get()” action. If using the POST verb, it will take you to the “Post([FromBody]Conference value)” action… and so forth. There is a conflict though when you try to go to ~/Conferences/GetCurrent (even though I have [ActionName(“current”)] on top):

Multiple actions were found that match the request:
System.Collections.Generic.IEnumerable1[MyApp.Models.Conference]
Get() on type MyApp.Api.ConferencesController
System.Collections.Generic.IEnumerable
1[MyApp.Models.Conference]
GetCurrent() on type MyApp.Api.ConferencesController

This implies the framework is using StartsWith instead of Equal to determine a default action. Also it is ignoring the ActionName attribute when matching verb to action.

My question is how do I make the framework’s default action to match to the verb exactly, instead of using StartsWith logic? A GET verb should match only a Get() action, not Get(), GetCurrent() GetPast(), etc (especially when it is ignoring the ActionName attribute).

EDIT
For simplicity, I only showed one of my routes above. I think it may help if I show all my routes which is still in draft. I am trying to get a fully working REST API while still leaving room for adding my own custom actions:

    public static void Register(HttpConfiguration config)
    {
        config.Routes.MapHttpRoute(
            name: "DefaultApiControllerActionId",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: null,
            constraints: new { action = @"^[a-zA-Z]+$", id = @"^\d+$" } // action must start with character
        );

        config.Routes.MapHttpRoute(
            name: "DefaultApiControllerActionName",
            routeTemplate: "api/{controller}/{action}/{name}",
            defaults: null,
            constraints: new { action = @"^[a-zA-Z]+$", name = @"^[a-zA-Z]+$" } // action and name must start with character
        );

        config.Routes.MapHttpRoute(
            name: "DefaultApiControllerId",
            routeTemplate: "api/{controller}/{id}",
            defaults: null,
            constraints: new { id = @"^\d+$" } // id must be all digits
        );

        config.Routes.MapHttpRoute(
            name: "DefaultApiControllerAction",
            routeTemplate: "api/{controller}/{action}",
            defaults: null,
            constraints: new { action = @"^[a-zA-Z]+$" } // action must start with character
        );

        config.Routes.MapHttpRoute(
            name: "DefaultApiController",
            routeTemplate: "api/{controller}"
        );

UPDATE
It seems that adding HTTP verb contraints helped:

        config.Routes.MapHttpRoute(
            name: "DefaultApiControllerGet",
            routeTemplate: "api/{controller}",
            defaults: new { action = "Get" },
            constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) }
        );

        config.Routes.MapHttpRoute(
            name: "DefaultApiControllerPost",
            routeTemplate: "api/{controller}",
            defaults: new { action = "Post" },
            constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Post) }
        );

        config.Routes.MapHttpRoute(
            name: "DefaultApiControllerPut",
            routeTemplate: "api/{controller}",
            defaults: new { action = "Put" },
            constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Put) }
        );

        config.Routes.MapHttpRoute(
            name: "DefaultApiControllerDelete",
            routeTemplate: "api/{controller}",
            defaults: new { action = "Delete" },
            constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Delete) }
        );
  • 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-17T17:20:03+00:00Added an answer on June 17, 2026 at 5:20 pm

    EDIT: Since you made a big edit to the question, I need to change the response:

    In short – this will never work out of the box with Web API, because it will by default dispatch the action:

    1. based on action name if {action} is part of the route data
    2. based on HTTP verb

    However, these two approaches cannot be mixed in a single controller, so you will not be able to dispatch actions using both approaches from a single controller (which is what you are trying to do).

    You have three ways to fix this:

    1. rework your resources, so that you have separate ones for action-name dispatching and verb-based disptaching (which is far from ideal)

    2. register routes manually for every of the nested routes. This way you keep dispatching by HTTP verb, but routing clearly points to a specific action. You could use something like AttributeRouting (https://github.com/mccalltd/AttributeRouting) to simplify this. The downside is obviously you end up with – effectively – one route per action

    3. Implement a new IActionSelector which would allow you to mix both Verb based and action-name based dispatching in a single controller. This is the most “low-level” solution, but seems exactly like something you want to do. I posted a walkthrough last week – http://www.strathweb.com/2013/01/magical-web-api-action-selector-http-verb-and-action-name-dispatching-in-a-single-controller/

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

Sidebar

Related Questions

Seems there's nothing to do… using the combo prototype/lowpro, no problems at all with
It seems there are many ways to do this, however, none of them make
It seems there are no free* .NET performance profilers that can profile on a
I am trying to read command lien argument but it seems there is some
My app has a registered shutdown function and it seems there's some issues with
I'm trying to create a branch from a remote tag, but it seems there's
after browsing the documentation for the sound classes, it seems there is no way
Seems like there should be... Right now it just seems like magic that you
There seems to be a breaking (i.e. backwards-incompatible) change in the CSS Syntax Module
There seems to be a lot of questions asking for regex to detect a

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.