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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:35:22+00:00 2026-06-15T02:35:22+00:00

I am looking for tips on how to set up routing in a Web

  • 0

I am looking for tips on how to set up routing in a Web API project. I have set up a controller called Resident with a method as follows:

public ResidentModel GetResidentInfo(int resId)
{
    //code to return ResidentModel object 

}

I have tried the following to map to this method in the route.config file.

 routes.MapRoute(
            name: "Resident",
            url: "{controller}/{action}/{id}",
            defaults: new {  id = UrlParameter.Optional }
            );

I am trying to access this method through a variety of ways:

http://localhost/resident/1 or 
http://localhost/resident/GetResidentInfo/1 etc... 

I’m looking for some guidance on the process of setting up a controller then mapping to that controller method as when I try to access methods I’ve created it does not recognize them. Thanks in advance.

  • 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-15T02:35:23+00:00Added an answer on June 15, 2026 at 2:35 am

    First, your controller class should be called ResidentController (not just Resident) and inherit from ApiController (it really needs to implement IHttpController, but inheriting from that class is the easiest way).

    Second, you should use MapHttpRoute instead of MapRoute for Web API controllers.

    Next, the paramter id on the route doesn’t match the parameter in your action. If you have a route such as the one below, you should be able to get to the second URL:

    routes.MapHttpRoute(
        name: "WithAction",
        routeTemplate: "{controller}/{action}/{resId}");
    

    And this would match the first one:

    routes.MapHttpRoute(
        name: "DefaultAction",
        routeTemplate: "{controller}/{resId}",
        defaults: new { action = "GetResidentInfo" });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking for tips/tools to make this happen (using PDF/Velocity Templates/Java): I have an image
I'm looking for tips on how to implement the popular 'paper folding / origami'
I'm looking for tips and ideas on how to best incorporate authentication with PHP
I am looking for some tips how to read strings from a remote server
I am looking for any tips or resources on importing from excel into a
I'm looking for some tutorials/resources/tips that will show me how to run applications via
Looking to do a bit of refactoring... Using NHibernate I have this query currently
Looking for some docs/tips on how to use Property Injection in an MVC solution
I am looking to use a database project in visual studio 2010 so that
So i have a set of four points in 3D Space. P1 [0, 0,

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.