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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:58:19+00:00 2026-05-11T00:58:19+00:00

ASP.NET MVC routes have names when mapped: routes.MapRoute( Debug, // Route name — how

  • 0

ASP.NET MVC routes have names when mapped:

routes.MapRoute(     'Debug', // Route name -- how can I use this later????     'debug/{controller}/{action}/{id}',     new { controller = 'Home', action = 'Index', id = string.Empty } ); 

Is there a way to get the route name, e.g. ‘Debug’ in the above example? I’d like to access it in the controller’s OnActionExecuting so that I can set up stuff in the ViewData when debugging, for example, by prefixing a URL with /debug/…

  • 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. 2026-05-11T00:58:20+00:00Added an answer on May 11, 2026 at 12:58 am

    The route name is not stored in the route unfortunately. It is just used internally in MVC as a key in a collection. I think this is something you can still use when creating links with HtmlHelper.RouteLink for example (maybe somewhere else too, no idea).

    Anyway, I needed that too and here is what I did:

    public static class RouteCollectionExtensions {     public static Route MapRouteWithName(this RouteCollection routes,     string name, string url, object defaults, object constraints)     {         Route route = routes.MapRoute(name, url, defaults, constraints);         route.DataTokens = new RouteValueDictionary();         route.DataTokens.Add("RouteName", name);          return route;     } } 

    So I could register a route like this:

    routes.MapRouteWithName(     "myRouteName",     "{controller}/{action}/{username}",     new { controller = "Home", action = "List" }     ); 

    In my Controller action, I can access the route name with:

    RouteData.DataTokens["RouteName"] 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asp.net mvc application with a route similar to: routes.MapRoute(Blog, {controller}/{action}/{year}/{month}/{day}/{friendlyName}, new
I'm trying to use route constraints in an Asp.Net MVC Application. routes.MapRoute( theRoute, MyAction/{page},
This is ASP.NET MVC v1 (not using the v2 yet) I have a route
I have a route in my asp.net mvc 2 site that looks like this
Is there a way to force use of a named route in ASP.NET MVC
ASP.NET MVC - what is this in VB.NET? Html.TextBox( name, null, new { @class
This is going to sound quite bizarre. I have one ASP .NET MVC 2
guy, i have a page in my asp.net mvc website. the Route configuration: public
I've started with ASP.NET MVC recently, reading blogs, tutorials, trying some routes, etc. Now,
I'm having some trouble with ASP.NET MVC Beta, and the idea of making routes,

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.