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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:47:44+00:00 2026-05-23T18:47:44+00:00

I really like the ASP.NET MVC 3 framework. Or at least, it sure is

  • 0

I really like the ASP.NET MVC 3 framework. Or at least, it sure is incomparably better than trying to fool with ASP.NET 3.5 or 4.0. However, I am just really confused about something. Why did they choose to specify routes with strings?

IOW, I am told to specify my routes like this (for instance):

... new { controller = "Products", action = "List", id = UrlParameter.Optional }

This route matches a ProductsController.List() method. Let’s say I’m in a refactoring mood and I want to rename my ProductsController to InventoryController. After using my renaming tool of choice, I have open up Global.aspx and go through all my routes and change all these stupid strings to “Inventory”. You might respond that I can do a find and replace… but come on! I feel like that is such a last-generation answer.

I love refactoring my code as I come to understand my domain better. I don’t want to use stupid (I say stupid because they have no significance to the compiler) strings to refer to symbolic/semantic code constructs that correspond exactly to type and method names that are ultimately stored in a symbol table. What is the point? Why bother with types at all? Let’s just go back to writing scripts using associative arrays and dictionaries to represent our domain model… it seems to me that the benefit of strong typing is greatly lessened when we mix it with string references.

Seriously, though, an option would be reflection. Would there be a performance hit for this? I suppose the MVC framework must be using reflection on that “Products” string to get my ProductsController, so… But also, you would have to remove the “Controller” portion of the type name, as follows:

= typeof(ProductsController).Name.Replace("Controller", string.Empty)

I could use the following helper function to make it a little DRYer:

public string GetControllerName(Type controller)
{
    return controller.Name.Replace("Controller", string.Empty);
}

Benchmarking is in order, if this is the only way to avoid those strings… Still, this is stupid. I’m using reflection on a type to get a string that MVC is going to use in conjunction with reflection to get the type I originally had in the first place.

Is there some reason not take the next (logical?) step and have the controller and action properties expect Types and Delegates directly? Wouldn’t this simply be cleaner and clearer? So far as I understand, a fundamental aspect of MVC is convention over configuration, but routing with those strings just seems to be a furtive form of configuration to me.

Is there another way around this? I am still new to MVC. I’ve read that we can replace these routing components. Does anyone know if it is possible to do what I’m talking about? And if it’s not possible, well… am I alone here? Am I missing something? Some overriding reason why it is essential that these routes be set by dumb strings? If not, could this maybe be something to lobby for?

Am I alone in hating it when strings are used in this way? I still think C# needs something akin to Ruby’s symbols and Lisp’s keywords that our refactoring tools could take advantage of. Sort of like “string enumerations” where the enumeration value name is at the same time the value.

I understand that parts of this question are subjective, but I am also looking for the objective answer on whether it is possible to directly use types and delegates to specify these routing configurations.

Thank you,
Jeromeyers

  • 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-23T18:47:44+00:00Added an answer on May 23, 2026 at 6:47 pm

    Personally I never had problems with the way routes are defined because I always unit test them. So if I am in a refactoring mood, my unit tests always guarantee me that the routes will behave as I want.

    Of course if you are still not satisfied with the way the ASP.NET MVC team designed the framework (don’t hesitate to open a ticket and vote for improvement in future versions) you could always write a custom route:

    public class IHateMagicStringsRoute<T> : Route where T : Controller
    {
        public IHateMagicStringsRoute(
            string url,
            Expression<Func<T, ActionResult>> expression
        ) : base(url, Parse(expression), new MvcRouteHandler())
        { }
    
        private static RouteValueDictionary Parse(Expression<Func<T, ActionResult>> expression)
        {
            var mce = expression.Body as MethodCallExpression;
            if (mce != null)
            {
                return new RouteValueDictionary(new
                {
                    controller = typeof(T).Name.Replace("Controller", ""),
                    action = mce.Method.Name
                });
            }
            return null;
        }
    }
    

    and then instead of:

    routes.MapRoute(
        "Default",
        "{controller}/{action}",
        new { controller = "Home", action = "Index" }
    );
    

    you could:

    routes.Add(
        new IHateMagicStringsRoute<HomeController>(
            "{controller}/{action}",
            x => x.Index()
        )
    );
    

    Now you can rename your controllers and actions as much as you like.

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

Sidebar

Related Questions

Answers like ASP.NET MVC or Entity Framework really aren't acceptable as they address just
I really like the MVC way and have actually enjoyed learning ASP.NET MVC (I
First of all, I'm really new to the MVC Asp.Net ideology. I would like
I’m new to asp.net and the mvc framework and I’m trying to learn by
I really like the way ASP.NET MVC works. I'd love to implement it on
EDIT: Guys, sure I meant Entity Framework not ASP.NET MVC, it was a typo
I am currently starting to dive into asp.net mvc and I really like what
I am using ELMAH in my ASP.NET MVC projects and I really like its
I am re-designing an application for a ASP.NET CMS that I really don't like.
I'm implementing a web API using the REST for ASP.NET MVC framework (MVC 2).

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.