DZone
Web Dev Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Web Dev Zone > ASP.NET MVC 4: Where Have All The Global.asax Routes Gone?

ASP.NET MVC 4: Where Have All The Global.asax Routes Gone?

Wondering where all the global.asax routes have gone today? Read on and find out.

Jon Davis user avatar by
Jon Davis
·
Jun. 24, 12 · Web Dev Zone · Analysis
Like (0)
Save
Tweet
15.69K Views

Join the DZone community and get the full member experience.

Join For Free

i ran into this a few days back and had been meaning to blog about it, so here it finally is while it’s still interesting information.

in asp.net mvc 1.0, 2.0, and 3.0, routes are defined in the global.asax.cs file in a method called registerroutes(..).

mvc3_register_routes

it had become an almost unconscious navigate-and-click routine for me to open global.asax.cs up to diagnose routing errors and to introduce new routes. so upon starting a new asp.net mvc 4 application with visual studio 11 rc (or visual studio 2012 rc, whichever it will be called), it took me by surprise to find that the registerroutes method is no longer defined there. in fact, the mvcapplication class defined global.asax.cs contains only 8 lines of code! i panicked when i saw this. where do i edit my routes?!

mvc4_globalasax

what kept me befuddled for far too long (quite a bit longer than a couple seconds, shame on me!) was the fact that these lines of code, when not actually read and only glanced at, look similar to the application_start() from the previous iteration of asp.net mvc:

mvc3_globalasax

eventually i squinted and paid closer attention to the difference, and then i realized that the registerroutes(..) method is being invoked still but it is managed in a separate configuration class. is this class an application settings class? is it a poco class? a wrapper class for a web.config setting? before i knew it i was already right-clicking on registerroutes and choosing go to definition ..

mvc4_globalasax_gotodef

under tools –> options –> projects and solutions –> general i have track active item in solution explorer enabled, so upon right-clicking an object member reference in code and choosing “go to definition” i always glance over at solution explorer to see where it navigates to in the tree. this is where i immediately found the new config files:

mvc4_app_start_solex

.. in a new app_start folder, which contains filterconfig.cs, routeconfig.cs, and bundleconfig.cs, as named by the invoking code in global.asax.cs. and to answer my own question, these are poco classes, each with a static method (i.e. registerroutes).

i like this change. it’s a minor refactoring that cleans up code. i don’t understand the naming convention of app_start, though. it seems like it should be called “config” or something, or else global.asax.cs should be moved into app_start as well since application_start() lives in global.asax.cs. but whatever. maintaining configuration details in one big global.asax.cs file gets to be a bit of a pain sometimes especially in growing projects so i’m very glad that such configuration details are now tucked away in their own dedicated spaces.

i am curious but have not yet checked to determine whether app_start as a new asp.net folder has any inherent behaviors associated with it, such as for example post-edit auto-compilation. i’m doubtful.

in future blog post(s), perhaps my next post, i’ll go over some of the other changes in asp.net mvc 4.

ASP.NET MVC ASP.NET

Published at DZone with permission of Jon Davis, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How to Leverage Method Chaining To Add Smart Message Routing in Java
  • Why I'm Choosing Pulumi Over Terraform
  • After COVID, Developers Really Are the New Kingmakers
  • What SREs Can Learn From the Atlassian Nightmare Outage of 2022

Comments

Web Dev Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo