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

  • Home
  • SEARCH
  • 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 338849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:28:04+00:00 2026-05-12T10:28:04+00:00

I would like to learn how setup prefix routing like there is in cakephp

  • 0

I would like to learn how setup prefix routing like there is in cakephp for admin routing. Unfortunately I have not figured out how to do this in ASP.NET MVC.

For example,

If the user types in /Admin/Management, I would like controller Management.admin_index to be called, without changing the url. I tried what I thought was correct but it ended up changing all my urls.

So the question is: If it is possible, how do I do prefix routing in ASP.NET MVC?

Update: This is exactly what I was looking for. http://devlicio.us/blogs/billy_mccafferty/archive/2009/01/22/mvc-quot-areas-quot-as-hierarchical-subfolders-under-views.aspx This code allows you to have a default website, and then an admin area.

  • 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-05-12T10:28:04+00:00Added an answer on May 12, 2026 at 10:28 am

    Maybe you should try writing a custom route. Look at System.Web.Routing.RouteBase.

    * edit *

    Ok, I had another look and I was wrong. What was initially my first thought turned out to be the easier solution: you should implement a custom IRouteHandler like this:

    using System.Web;
    using System.Web.Mvc;
    using System.Web.Routing;
    
    namespace PrefixRoutingTest.Util
    {
        public class PrefixRouteHandler : IRouteHandler
        {
            public IHttpHandler GetHttpHandler(RequestContext requestContext)
            {
                //only apply this behavior to a part of the site
                if (requestContext.HttpContext.Request.Path.ToLower().StartsWith("/prefixed/") &&
                    requestContext.HttpContext.User.Identity.IsAuthenticated)
                {
                    //prefix the action name with Admin
                    var action = requestContext.RouteData.Values["action"].ToString();
                    requestContext.RouteData.Values["action"] = "Admin" + action;
                }
    
                return new MvcHandler(requestContext);
            }
        }
    }
    

    Then, make a controller with two actions, prefix one of them with ‘Admin’, and mark it with the AuthorizeAttribute. It should look something like this:

    using System.Web.Mvc;
    
    namespace PrefixRoutingTest.Controllers
    {
        public class PrefixedController : Controller
        {
            public ActionResult Test()
            {
                return View();
            }
    
            [Authorize]
            public ActionResult AdminTest()
            {
                return View();
            }
    
        }
    }
    

    Make a ‘Prefixed’ folder in the Views folder and add two Views in it, a Test.aspx and a AdminTest.aspx. Then you just need to replace the default route (in Global.asax) with this code:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
        routes.Add("Default", new Route("{controller}/{action}/{id}", new PrefixRouteHandler())
        {
            Defaults = new RouteValueDictionary(new { controller = "Home", action = "Index", id = "" })
        });
    }
    

    And that’s it, when you now navigate to site/Prefixed/Test as an anonymous user you should get the standard Test view, but if you are an admin you will get the AdminTest view. If an anonymous user, however, tries to access AdminTest url directly he will be sent to the login page.

    PS: I can confirm this works, sou if you have problems implementing it just give me a ring 😉

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

Sidebar

Related Questions

I have a problem and i would like to learn the correct way to
I am a totally blind programmer who would like to learn Python. Unfortunately the
I would like to make a simple desktop application to learn this kind of
I have CLI/MFC application and I would like to begin to learn how to
Trying to solve this problem . I would like to learn how the bootstrapper
I'm trying to learn how to use ivy and would like to setup a
I would like to learn more about C++0x. What are some good references and
I would like to learn the best practices to employ when creating a database
I would like to learn the best practices in reloading the application state, such
I'm a totally blind individual who would like to learn more of the theory

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.