Converting ASP.NET Dynamic Data Web Application to Web Site Project

Hello folks,

Today, I want to make an "Admin" section for my web site, in order to provide an easy interface for me to manage my database. I already have the web site running as an ASP.NET 4.0 Web Site project. So what I will do is, create a Dynamic Data Web Application and convert the project from Web Application to Web Site so I can add it into the Admin folder on my existing web site.

This post is not going into the details of the differences between Web Site and Web Application, so here is the official reference: Comparing Web Site Projects and Web Application Projects

Microsoft’s walkthrough demonstrates how to convert web site to web application, but what I want to do is the other way around. First, let’s create the Dynamic Data project:

  1. Open Visual Studio 2010 and choose to create a new Dynamic Data Web Application project. Name it "Admin".
  2. Delete *.designer.cs on every folder from all ascx and aspx pages including the master page.
  3. For every page, replace the first line from "CodeBehing" to "CodeFile". You can use the Replace in Files tool for that.
  4. <%@ Page Language="C#" MasterPageFile="~/Site.master" CodeFile="Default.aspx.cs" Inherits="Admin.Default" %>
  5. Close the project.
  6. Via Windows Explorer, delete:
    • The project files (.csproj and csproj.user)
    • The config files from the root folder only, (web.config, web.release.config and web.debug.config)
    • App_data, Bin, Properties and obj folders.
  7. Select File > Open Web Site and select the web site or create a new one.
  8. Create a new folder: "Admin". Right-click and select Add Existing Item… Add all files from the original project (excluding global.asax and global.asax.cs).
  9. Now we need to write code onto Global.asax based on the original Global.asax.cs file:
    • First, select the web site root and right-click to add an App_Code folder
    • Create a static class into App_Code, name it Global:
    using System.Web.DynamicData;
    public static class Global
       private static MetaModel s_defaultModel = new MetaModel();
        public static MetaModel DefaultModel
               s_defaultModel.DynamicDataFolderVirtualPath = "~/Admin/DynamicData/";
  10. As you can see, there’s a slightly diference which is the addition of the Admin folder to the DynamicDataFolderVirtualPath. Do the same when adding the route on the Global.asax:
  11.       <%@ Application Language="C#" %>
          <%@ Import Namespace="System.Web.Routing" %>
          <%@ Import Namespace="System.Web.DynamicData" %>
          <script runat="server">
              public static void RegisterRoutes(RouteCollection routes)
                  Global.DefaultModel.RegisterContext(typeof(MyContext), new ContextConfiguration() {
          ScaffoldAllTables = true });
                  routes.Add(new DynamicDataRoute("Admin/{table}/{action}.aspx")
                     Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
                     Model = Global.DefaultModel
              void Application_Start(object sender, EventArgs e)
  12. Add the respective references to the web site project: System.Web.Routing, System.Web.DynamicData
  13. Replace MyContext to your context. To know more about this, read the Walkthrough: Creating a New ASP.NET Dynamic Data Web Site Using Scaffolding
  14. Pay attention to the absolute path ~/ change them respectively to ../ or ../../ for the Site.master
  15. Try to complie now, you will see that it won’t work because we need to change the Admin folder’s Default.aspx.cs to point the DefaultModel on the Global class we just created.

4 thoughts on “Converting ASP.NET Dynamic Data Web Application to Web Site Project

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s