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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:10:00+00:00 2026-06-12T15:10:00+00:00

I am using web api with ASP.NET MVC 4. I have the following named

  • 0

I am using web api with ASP.NET MVC 4.

I have the following named controller

  • CustomerController : Controller
  • CustomerApiController : ApiController

Earlier my CustomerApiController was named CustomersController so to access it, I simply had to punch in the following url

localhost/api/Customers

but now I have to keep the api controller name as CustomerApiController. I want to be able to hit the same method using localhost/api/Customers what changes do I have to make ?

I have tried making some changes in the RouteConfig.cs file. I tried adding the following to the RegisterRoutes method, but none of them worked.

routes.MapHttpRoute(
            name: "API Default",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

routes.MapRoute(
            name: "Customers",
            url: "api/customer/",
            defaults: new { controller = "CustomerApi", action = "Get", id = UrlParameter.Optional }
        );

Please can some one guide me on this. Thanks

  • 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-12T15:10:01+00:00Added an answer on June 12, 2026 at 3:10 pm

    Well there are two issues in your code. You are using MapRoute instead of MapHttpRoute. You should also put the more detailed route first so it will not get swallowed by more generic one:

    routes.MapHttpRoute(
        name: "Customer",
        url: "api/Customer/{id}",
        defaults: new { controller = "CustomerApi", action = "Get", id = UrlParameter.Optional }
    ); 
    
    routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{id}",
        defaults: new { id = RouteParameter.Optional }
    );
    

    Now if you want your solution to be more generic (when you have more controllers which need to be modified like this) you can use custom HttpControllerRouteHandler to transform incoming controllers names, this way you will be able to keep default routing.

    First you need to create custom HttpControllerRouteHandler:

    public class CustomHttpControllerRouteHandler : HttpControllerRouteHandler
    {
        protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            requestContext.RouteData.Values["controller"] = requestContext.RouteData.Values["controller"].ToString() + "Api";
    
            return base.GetHttpHandler(requestContext);
        }
    }
    

    Now you can register your HttpRoute like this:

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

    This way when you put Customer into URL the engine will treat it like CustomerApi.

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

Sidebar

Related Questions

I am using ASP.NET MVC 4 with Web Api I have the following ApiController.
Using the ASP.NET Web-Api, I have the following POST setup in my controller. When
I have an ASP.NET MVC 4 Web API app using EntityFramework for ORM. In
I'm implementing a web API using the REST for ASP.NET MVC framework (MVC 2).
I am using ASP.NET MVC 4 Beta with Web API - although I believe
I have a web application written in ASP .NET MVC 3. I'm using ACS
I am new to ASP.Net MVC and ASP.Net web api. I have worked on
I am developing some sort of service using asp.net mvc 4 web api. On
I am new to using ASP.NET MVC 4 with Web Api. I want to
I am creating a web api using asp.net mvc4 and the response output is

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.