Setting up Dynamicweb with ASP.NET MVC

In this how-to we outline how to set up Dynamicweb with ASP.NET MVC.

To get started:

  • Create a new project in Visual Studio:
  • Choose an ASP.NET Web Application (Figure 2.1)
Figure 2.1 Choose and ASP.NET Web Application
  • Choose an empty project with Web Forms and MVC folders added (Figure 2.2)
Figure 2.2 Empty project with Web Forms and MVC folder added
  • Add a reference to Dynamicweb.dll (Figure 2.3)
Figure 2.3 Referencing Dynamicweb.dll

From the Dynamicweb application, take web.config and replace the one in the newly created solution (after a backup has been taken).

This should be enough. Occasionally, settings from the solution web.config may have to be moved to the Dynamicweb web.config.

Next, make Global.asax call the Dynamicweb GlobalAsaxHandler.

Add the events exposed by Dynamicweb.

In Application_Start, keep the 2 lines that are originally in the Global.asax when the new Web Application was created and call Dynamicwebs GlobalAsaxHandler after the registration of Areas and Routes (Figure 4.1).

Figure 4.1 Altering Global.asax

Add an asp:placeholder control (Figure 5.1) and alter the code behind to load the PageViewControl in that placeholder.

Figure 5.1 Placeholder

Code behind (Figure 5.2):

Figure 5.2 Code behind

From the downloaded Dynamicweb application, copy the entire /Bin folder to the /Bin directory of the Web Application (Figure 6.1). Do this in File Explorer and not inside Visual Studio.

Figure 6.1 The bin folder

Setup Dynamicweb by following the normal steps in the installation guide.

  • Create a new website in IIS.
  • Add /Admin and /Files as virtual directories (Figure 7.1)
  • Install and configure a SQL Server database and make the changes in /Files/GlobalSettings.aspx accordingly.

Follow installation guide for more information.

Figure 7.1 Adding /admin and /files as virtual directories

You can now run a regular Dynamicweb.

Access the site in a browser to check it out, create a page and see it works (Figure 8.1).

Figure 8.1 Creating a page in /admin

Frontend (Figure 8.2):

Figure 8.2 The corresponding frontend

In the Visual Studio solution, add a Controller and a View (“Test” in this Figure 9.1).

Figure 9.1 Controller

In the Visual Studio solution, add a view for the controller (Figure 9.2).

Figure 9.2 View

Build the solution.

You can't build using F5 and start a debugging because of the way the solution has been set up. Instead, build using ALT+B+U and browse the solution in a browser. 

Navigate to the Controller /Test ({figurref}).

Figure 10.1 Running the MVC page

To debug the solution, in Visual Studio:

  • Go to Debug, Attach Process
  • Choose the w3wp process running the site. Remember to run VS in administrator mode.

As an alternative to attaching the process and enabling F5 debugging, instead of using /Files and /Admin as virtual directories, copy /Admin and /Files directly into the root folder of the Web Application.