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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:47:52+00:00 2026-06-13T09:47:52+00:00

In Global.asax we register routes using: MapRoute(this System.Web.Routing.RouteCollection routes, string name, string url, object

  • 0

In Global.asax we register routes using:

MapRoute(this System.Web.Routing.RouteCollection routes, 
    string name, 
    string url, 
    object defaults, 
    string[] namespaces)

Is there a way to retrieve the string url from code? Specifically, I am interested in getting route segments from the urls for registered routes like this:

"customRoutePrefix/{controller}/{action}/{id}"

I need to look up “customRoutePrefix” or the equivalent for any registered routes.

I thought I might be able to use System.Web.Routing.RouteTable.Routes to do this, but I haven’t found it in there.

Is this possible / how should I do this?

  • 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-13T09:47:53+00:00Added an answer on June 13, 2026 at 9:47 am

    Yes.

    You can use:

    this.RouteData.Values["segment name"]
    

    For example,

    this.RouteData.Values["controller"];
    

    Edit 1

    This piece of code will do the trick to retrieve all the registered routes URL’s

    var res = new List<string>();
    
    foreach (var item in RouteTable.Routes)
    {
        var r = (Route)item;
    
        res.Add(r.Url);
    }
    
    this.ViewBag.Res = res;
    

    In your view:

    @foreach (var item in this.ViewBag.Res)
    {
        <div>@item</div>
    }
    

    Results:

    Chapter14/{controller}/{action}/{id}
    Movies/{controller}/{action}/{id}
    api/{controller}/{id}
    {resource}.axd/{*pathInfo}
    {resource}.svc/{*pathInfo}
    {controller}/{action}/{id}
    wcf/{*pathInfo}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Application Object. In Global.asax file i use this: Application[obj] = test;
Here's what I'm trying to do in my Global.asax.vb: Public Class MvcApplication Inherits System.Web.HttpApplication
I'm using a configuration within the global.asax.cs to register the components but it looks
We are trying to remove the global.asax from our many web applications in favor
I'm using code in the Application_BeingRequest() handler of my Global.asax to do some very
Here's my Application_OnError event sink in global.asax.vb: Sub Application_OnError(ByVal sender As Object, ByVal e
I have registered a component like this in my Global.asax.cs: ContainerBuilder builder = new
I'm trying to get the URL segments of a page request in the global.asax
I'm using nUnit to test the routing of my MVC2 project. When I register
I'm able to successfully register a custom route handler (deriving from IRouteHandler) inside global.asax.cs

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.