ASP.NET 2.0 Guest Book Application

by agrace 4. February 2008 12:45

I recently had to create a Guest Book application for our local Tourism website. Googling a decent code sample didn't yield much so I created it from scratch. I'm making the code available at the bottom of this post. In an effort to keep things simple, I am leaving out the back-end administration since it basically uses the same database table. It also means that I do not have to walk through the membership sytem at this time. If I get requests, I may create another post on the admin part and update the code sample accordingly.

Add Comment


This is a Web Application project written in C#. There is a data access layer and a business layer. This may appear redundant for such a simple example as this but it does make for good coding habits! Ideally, one might also create a base page class and inherit from that, thus avoid unnecessary re-factorings later on. The App-Code folder is used to hold the business and data classes. Classes placed here are dynamically compiled which means we don't have to compile them separately.

Guest Book Message


If you place the source files for your classes in the App_Code folder, you must also add a reference to the System.Design assembly in the compilation section of the Web.config file. This reference requires the fully qualified assembly name of the System.Design assembly. You can get the information required for the fully qualified name by running the Global Assembly Cache Tool (Gacutil.exe) that ships with the Windows Software Development Kit (SDK), using the following syntax:

C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0>gacutil /l System.Design

I still make use of the SqlHelper class which came with the original "Data Access Application Block". Although this has been superceded by the Enterprise Library, I think it's much more appropriate for smaller projects. You can find out more here. When trying to incorporate the SqlHelper class into the project, I received the following error:

error CS0103: The name 'SqlHelper' does not exist in the current context

After you exhaust all that Google has to offer, you can try what I did and hack the project file by changing:

<content Include="App_Code\Data\SqlHelper.cs" />
<compile Include="App_Code\Data\SqlHelper.cs" />

Happy Days :-) 

Guest Book


Note that in the real-world you would use a CAPTCHA control. For simplicity I left it out here, but I originally used Peter Kellner's Ultimate CAPTCHA Control. It's easy to use and Peter was on hand to offer email assistance!

Feel free to download the code and use it any way you will! (74.71 kb) (3.13 kb)


View other SharePoint posts...

SharePoint Blues By now, you should have a fixed clone parent VM with the server OS installed and configured. You should also have a linked clone with VS 2005, SQL Server 2005 and any other developer tools you use frequently.

Before installing Microsoft SharePoint Server 2007 (MOSS), you need to configure SQL Server. If you do not see SQL Server Management Studio (SSMS) in your Start menu, install if from the client tools on your CD. This is not obvious! As mentioned previously, refer to Keith Pattons's blog postings for detailed steps.

Since this is purely a standalone development machine, you can use your Windows administrator COMPUTERNAME/Administrator login for the database also. Set up the roles as shown in the diagram below. In a production environment, you would first install the database and then set up seven separate domain accounts. Be sure to use the Surface Area Configuration Manager to enable TCP/IP and Named Pipes connections. Then, stop and re-start the database engine service for it to take effect. Also, set SQL Server "Maximum Server Memory" to half of that allocated to the VM. You can do this by right-clicking the server name in SSMS under properties. One more thing regarding the DB: if you plan on playing with Team System, note that it will not work with a "Developer" edition of SQL Server 2005.

SQL Server Roles


The next step is to install Microsoft SharePoint Server 2007 (MOSS). Create a new linked clone as before, and grab a free six-month trial of SharePoint here. In VMWare, right-click the drive icon in the task bar and select edit. Now, you can point it to the SharePoint ISO image you just downloaded to the desktop of your host PC. Choose the "Advanced" installation option. Then, on the "Server Type" tab, select the "Complete" option. Follow the steps outlined here. Since this is not a production machine and will not be joining a domain, you do not need to run Sysprep. After the install, you can run the configuration wizard. Aside from starting services and setting up email, note the following order of operations:

  * Create Shared Services Provider (configure index server first)
  * Create Web Application (and reset IIS using iisreset /noforce)
  * Create Site Collection

When you have things configured, run Windows Updates, as you should after each major install. Open Visual Studio at least once. Next, install the tools and extensions. This is the order in which I installed them:

  * Visual Studio Extensions for Windows SharePoint Services (VSeWSS)
  * Visual Studio Tools for Office Second Edition (VSTO)
  * Visual Extensions for Windows Workflow Foundation (VSeWWF)

Both VSTO and VSeWWF wil display success message panels after a successful installation. You can check for a successful installation of VSeWSS by opening Visual Studio and choosing to create a new project. If the install was successful, you should be able to see the SharePoint project templates shown below:

VSeWSS Extensions


Aside: Tips for Team Development Environment VM:
  * Sysprep the base VM
  * Do not use vOptimizer
  * Do not run the SharePoint Products and Technologies Wizard on the original VM

You should now be up and running. I have kept this series of blog posts brief and referred the reader to step-by-step instructions already covered by other blogs. The goal was to record my personal experience as I attempted to create a SharePoint development environment for my own learning purposes. This was an obvious first step before attempting the slightly more ambitious task of setting up a cloned team development VM. My machine is 3GHz, 2GB RAM and runs XP. My external drive is 160GB. My new environment works like a treat and is reasonably fast when running a single VM. Happy coding!


View other SharePoint posts...

At this point, you should have a snapshot of the base OS with the .NET frameworks and Office 2007 on board. Now we will create a linked clone in the Snapshot Manager and install the development tools. Tip: pick short, meaningful names for your VM instances so that you can make them out at a glance when you open Snapshot Manager. My layout has one more instance than the version described here, but it doesn't really matter. The main factors affecting performance are the external disk speed and available RAM. Note that some of the extensions need MOSS/WSS installed first, so that's why these installs are in a certain order.

Start by installing VS 2005. I'm using the standard version. Professsional is needed for Office development. The goal here is to be able to sit down at home and start developing. Even WSS on its own, which comes free with Windows Server 2003, is perfect to start coding against.

Snapshot Manager


When you have VS 2005 installed, download and install SP1 on its own. It's 431 MB and you may encounter error messages on Windows Server when you try to install it. Download a fix for the SP1 installation here. Note: I tried to install this using an ISO image on CD and had to right-click the icon first, select properties and then install the security certificate. Then apply the fix linked to above. This worked for me after much hassle; try to avoid the registry hack, more information here. Reboot, and install SP1: leave it run its course and do not be tempted to interrupt the install. If it's still running after a week, you can email me ;-)

At this stage, you should make a shortlist of the developer tools you normally work with, and install these also. Perhaps, the Firefox and IE7 developer toolbars, Notepad2, Reflector, etc.

Next, install SQL Server 2005. As with the other installs, you can install directly onto the VM using an ISO image. When in doubt, opt to install everything. Choose the Default Instance and Built-In System Account option. Select Local System from the drop-down list. Choose Windows Authentication Mode and select defaults for everything else. Re-boot if prompted, then run the updates. Download and install whatever is suggested.

SQL Server 2005


The next and final installment will see the installation of MOSS and the remaining extensions, including some things to look out for if you are trying to do this in a team environment...