ASP.NET Dynamic Data Preview - Mixing with "Static" Pages

The ASP.NET Dynamic Data Preview is essentially a powerful and flexible scaffolding framework for ASP.NET that allows you to very quickly create and customise data-driven ASP.NET applications. It does this by exploring the Linq to SQL data model and deriving the UI elements, navigation, validation etc from it.

Typically you would then customise the resulting application in a number of ways:

  • Customise and extending the model
  • Customise page templates
    • Globally (eg all List pages should look like this)
    • For individual entities (eg the "Homes" table List page should look like this)
  • Customise field rendering
    • Globally (eg for all booleans)
    • For individual fields (eg display "Price" using this Field format)

One question a lot of people have been asking is "Can I incorporate 'normal' ASP.NET pages in a Dynamic Data application?" (or vice-versa, can I incorporate some Dynamic Data pages in my existing ASP.NET app). The answer is of course yes; 'normal' ASP.NET pages and Dynamic Data pages sit quite happily together.

Dynamic Data takes advantage of the new routing capabilities that were developed for the MVC framework (which live in System.Web.Routing). By default, the routing mechanism ensures that any existing files on disk are not processed through the routing infrastructure but delivered directly.

If you delve into the code you'll find that the UrlRoutingModule (the HttpModule that hooks into the pipeline to manage routing) calls GetRouteData() on its RouteCollection and in GetRouteData() you'll find a check something like:

   if (!this.RouteExistingFiles)
    if (file_exists)
      return null;

In other words, if RouteExistingFiles is false (the default) we'll check if the file exists at the current relative file path before invoking the routing infrastructure. If the file exists, we're out of there pronto. If the file doesn't exist (or if RouteExistingFiles is true) we iterate over all the Routes in the RouteCollection looking for a match and hand off to the appropriate RouteHandler (ie we invoke the routing infrastructure).

What this means is, by default, any file that exists on disk essentially "trumps" any routing that's been established (there is also a secondary routing hierarchy as part of Dynamic Data whereby a custom page always takes precedence over the default page template but that's another story).

Dynamic data pages themselves are just standard ASP.NET pages (they derive from System.Web.UI.Page) and use the normal webforms model and page lifecycle to render (unlike MVC). Yes, they have some extra smarts in there to do the dynamic rendering but from a request / response perspective, they look pretty much like any other ASP.NET page.

BTW, if *do* you want every page routed, just set the RouteExistingFiles property of the RouteCollection object to true in the RegisterRoutes() method in Global.asax.

Technorati Tags:,dynamic data,routing,mvc


Technorati Profile