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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:08:38+00:00 2026-06-18T02:08:38+00:00

I am working on creating a Web API using ASP.NET Web API. I’m currently

  • 0

I am working on creating a Web API using ASP.NET Web API. I’m currently stubbing out functionality on my endpoints so that I can then start developing against it.

My WebApiConfig.cs file looks like this:

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

config.Routes.MapHttpRoute(
    name: "ActionAPI",
    routeTemplate: "api/{controller}/{id}/{action}",
    defaults: new { action = RouteParameter.Optional }
);

In my UsersController.cs file I have these methods:

//Maps to /Users endpoint
[HttpGet]
public IEnumerable<User> GetAllUsers()
{
   //Code
}

//Maps to /Users/{id} endpoint
[HttpGet]
public User GetUser(int id)
{
   //Code
}

//Maps to /Users/{id}/Enrollments endpoint
[HttpGet, ActionName("Enrollments")]
public IEnumerable<Enrollment> GetUserEnrollments(int id)
{
   //Code
}

//Maps to /Users/{id}/Enrollments/{id}
[HttpGet, ActionName("Enrollments")]
public IEnumerable<Enrollment> GetUserEnrollment(int userid, int id)
{
   //Code
}

How do I prevent /Users/GetUser from being a valid route?

Using [NonAction] on GetUser(int id) prevents it from working completely.

EDIT: Here is the current output from /Users/GetUser

<Error>
    <Message>An error has occurred.</Message>
    <ExceptionMessage>
        Multiple actions were found that match the request: Byui.ILearnAPI2.Business.Entities.User GetUser(Int32) on type Byui.ILearnAPI2.API.Controllers.UsersController System.Collections.Generic.IEnumerable`1[System.String] GetUserEnrollments(Int32) on type Byui.ILearnAPI2.API.Controllers.UsersController
    </ExceptionMessage>
    <ExceptionType>System.InvalidOperationException</ExceptionType>
    <StackTrace>
at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controllerContext) at System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext) at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken) at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncInternal(HttpRequestMessage request, CancellationToken cancellationToken) at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    </StackTrace>
</Error>
  • 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-18T02:08:39+00:00Added an answer on June 18, 2026 at 2:08 am

    After reviewing your post again, I think that you are not looking at the error correctly.

    Because of the way you have your controller configured, there is an ambiguous route.

    Multiple actions were found that match the request:

    GetUser(Int32) on type Byui.ILearnAPI2.API.Controllers.UsersController

    GetUserEnrollments(Int32) on type Byui.ILearnAPI2.API.Controllers.UsersController

    GetUser and GetUserEnrollments share the same route. From what I can tell GetUser is not going to work if you pass it an int or a string or whatever, because it does not know how to resolve properly.

    You can add a route config before your default to resolve the issue.

    config.Routes.MapHttpRoute(
        name: "GetUsers",
        routeTemplate: "api/users/{id}",
        defaults: new { controller = "Users", action = "GetUser" }
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a web application using ASP.Net. I am using session in my
When creating a default ASP.NET Web Api project, default ValuesController has post method like
I'm working with Asp.net WebApi that has forms authorization. I've succeeded in creating POST
I'm currently working on some web services network (ASP.NET 3.5 web services). My business
I am working on creating a Web site like www.hipmunk.com in ASP.NET web forms.
I'm working on a self-hosted ASP.NET web api-application. Everything works fine, but now I'm
I am working on creating a web app that will query event logs on
I am used to working with ASP web apps and creating .aspx pages. I
I am working on creating a blog with ASP.Net 4, MVC 3, Razor and
I'm working on creating a WCF web service that communicates via JSON. I got

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.