Welcome to MSDN Blogs Sign in | Join | Help

How to add Dynamic Data to an Existing Web Application

Yesterday I posted about how to add Dynamic Data to an existing website and I got some feedback about how to add Dynamic Data to an existing web application. Web application projects work a little different the website projects, you can check out the differences here: http://msdn.microsoft.com/en-us/library/aa730880(VS.80).aspx.

1) Create a dummy Dynamic Data web application project. Copy the DynamicData directory from it into your existing web application. You should also copy the Site.css and Site.master files. The Default.aspx file is optional, it display a menu of tables in your data model, this file is only needed if you plan on having such a menu in your application. IMPORTANT: Web application projects have namespaces in their code behind files, you may want to change the namespaces of the copied in files to match the namespace of your existing project. 

2) You can copy the Global.asax file or if you already have such a file you can just add the model registration and url routes as below to the

<%@ Import Namespace="System.Web.Routing" %>
<%@ Import Namespace="System.Web.DynamicData" %>

void Application_Start(object sender, EventArgs e) {

MetaModel model = new MetaModel();

model.RegisterContext(typeof(YourDataContextType), new ContextConfiguration() { ScaffoldAllTables = false });

routes.Add(new DynamicDataRoute("{table}/{action}.aspx") {
    Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
    Model = model
});

}

3) Right click on the References node in the solution explorer and select "Add Reference". In the dialog that opens up you need to select System.ComponentModel.DataAnnotations, System.Web.Abstractions, System.Web.DynamicData and System.Web.Routing.

4) In the <compilation> section in web.config add the following assemblies:

<add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.ComponentModel.DataAnnotations, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.DynamicData, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

5) In the <pages>/<controls> section add the following new tag prefix:

<add tagPrefix="asp" namespace="System.Web.DynamicData" assembly="System.Web.DynamicData, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

6) Enable the new ASP.NET Routing feature:

IIS 5/6/Casini

In the <httpModules> section add the following new module:

<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

IIS 7

In the <system.webServer>/<modules> section add the following:

<remove name="UrlRoutingModule" />

<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

In the <system.webServer>/<handlers> section add the following:

<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

 

At this point Dynamic Data should be functional. To enable it see the steps at the bottom of yesterdays post.

Published Tuesday, June 24, 2008 1:18 AM by scothu

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Pregnant Man &raquo; How to add Dynamic Data to an Existing Web Application

# Adding Dynamic Data to Existing ASP.NET Sites

I posted back in May about the ability to combine standard ASP.NET webforms pages and ASP.NET Dynamic

Friday, June 27, 2008 10:51 AM by Mike Ormond's Blog

# Dynamic Data Deep Dive

Listen to the Show! When first introduced to Dynamic Data , developers often write the technology off

Wednesday, July 02, 2008 11:35 AM by Craig Shoemaker

# ASP.NET Dynamic Data geekSpeak Q&A and Follow Up

Below are a list of questions directly from my geekSpeak session earlier this week. Q: How do you hide a class from the scaffolding? A: Use the ScaffoldTableAttribute on the class in your data model you want to hide. [ ScaffoldTable ( false )] public

Sunday, October 05, 2008 11:36 PM by Rachel Appel Blog

# ASP.NET Dynamic Data geekSpeak Q&A and Follow Up

Below are a list of questions directly from my geekSpeak session earlier this week. Q: How do you hide

Monday, October 06, 2008 12:19 AM by ASPInsiders

# re: How to add Dynamic Data to an Existing Web Application

Instead of routes.Add(), I had to use RouteTable.Routes.Add().

Monday, December 29, 2008 12:50 PM by Scott Kowalczyk

# re: How to add Dynamic Data to an Existing Web Application

Shouldn't you also add <remove name="UrlRoutingHandler" /> under <system.webServer>/<handlers> section?

Thursday, January 29, 2009 4:41 PM by Girish

# re: How to add Dynamic Data to an Existing Web Application

# re: How to add Dynamic Data to an Existing Web Application

Be aware when copying page and control files!!! You can get "...does not exist in the current context" compiler errors. Reason for this is that the designer files are not included in the project automatically.

http://forums.asp.net/t/1437727.aspx

Wednesday, July 22, 2009 4:36 AM by Branko

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker