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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:41:45+00:00 2026-06-11T21:41:45+00:00

I have a number of controllers in application: ApiV1Controller ApiV2Controller ApiV3Controller … Is it

  • 0

I have a number of controllers in application:

ApiV1Controller
ApiV2Controller
ApiV3Controller
...

Is it possible to map routes for them with single MapRoute statement to URLs like /api/v1/{action}?

  • 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-11T21:41:47+00:00Added an answer on June 11, 2026 at 9:41 pm

    You could write a custom route. Let’s suppose that you have the following controllers:

    public class ApiV1Controller : Controller
    {
        public ActionResult Index()
        {
            return Content("v1");
        }
    }
    
    public class ApiV2Controller : Controller
    {
        public ActionResult Index()
        {
            return Content("v2");
        }
    }
    
    public class ApiV3Controller : Controller
    {
        public ActionResult Index()
        {
            return Content("v3");
        }
    }
    

    Now write a custom route:

    public class ApiRoute : Route
    {
        public ApiRoute()
            : base("api/{version}/{action}", new RouteValueDictionary(new { action = "index" }), new MvcRouteHandler())
        {
        }
    
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            var rd = base.GetRouteData(httpContext);
            if (rd == null)
            {
                return null;
            }
    
            rd.Values["controller"] = "Api" + rd.GetRequiredString("version");
            return rd;
        }
    }
    

    That could be registered in your Global.asax:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
        routes.Add("ApiRoute", new ApiRoute());
    
        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );
    }
    

    and that’s pretty much it. Now you could play with urls:

    • /api/v1
    • /api/v2
    • /api/v3
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a number of Controllers, and I want them all to have an
I have a basic ASP.Net MVC 3 application which has a number of controllers
I have a navigation controller based application. There are a number of view controllers.
I have a tab-based application with a number of navigation controllers in the tabs.
I have a C++ application that includes a number of structures with manually controlled
I have 3 folders in my root, application, system, and uploads. In application/controllers/mycontroller.php I
I am writing an ASP.NET MVC 3 application and I have a number of
I have been reading a number of tutorials on implementing Structure Map IoC/di into
I have this simple MVC 3 application which simply has two controllers(Home and Edit),
In Rails3 application i have a number of models with user_id - this way

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.