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

Ask A Question

Stats

  • Questions 182k
  • Answers 182k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Ok now I've done my research, here is the deal:… May 12, 2026 at 4:27 pm
  • Editorial Team
    Editorial Team added an answer Elementary vector algebra. O — center of circle (vector) r… May 12, 2026 at 4:27 pm
  • Editorial Team
    Editorial Team added an answer Craig Hockenberry posted a script here that will let you… May 12, 2026 at 4:27 pm

Related Questions

I am looking to start working on a personal site using C#. I work
Time ago I started to develop a project and now I would like to
What do I want to achieve? We are currently working on a PHP project
I'm trying to learn how to use ivy and would like to setup a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.