Skip navigation.

How to Link Stylesheets from a Master Page (Part 2)All recent postsWhat's New in Web Server Controls

How to Create a Multi-Tiered Web Application in Visual Studio 2005

When we set out to break ground with 2.0 on a recent internal project, I noticed it wasn’t obvious how to set up a multi-tiered web app in Visual Studio 2005 (I just now noticed there’s no .NET in the Visual Studio name anymore). By trial and error I did figure it out and wanted to share my step-by-step process.

I suppose I do not have to talk about the benefits of splitting a web app into tiers, such as Data Access, Business Logic, Domain, Presentation, Façade, etc. I think we’ve all learned a fair bit about building such apps with VS 2K3 as Microsoft’s architectural guidance gradually changed since 2000.

At first, DataSets were all the rage with open DataReaders in the UI tier (does anyone remember the old Pet Store code by Vertigo?). Then things got a little more organized with domains, entities, custom collections and so forth. It was a necessary evolution and a learning experience to everyone. As a side note, I’d like to see the Domain Driven Design embraced by this community better.

When VS 2K5 shipped I was surprised it had only the Web Site model, i.e. one web site with everything dumped into the same pot. Placing stand-alone classes into App_Code would work for short term and within a small project, but it doesn’t make good architecture. The Web Site project model has its place under the sun, but only as a younger sister of the Web Application model.

I really do not understand how such a feature could disappear from Visual Studio after so many projects have been developed with it. I also don’t understand why folks at Microsoft had to reinvent the wheel by developing it on the side. I’m sure somebody has an explanation.

Let’s Build a Sample Project

Suppose we want to set up a project with the following tiers:

  • DataAccess
  • BusinessLogic
  • Framework
  • Web

Discussing architecture is like arguing about religion. This is only an exercise, so bear with me.

You need to first download the Web Application Project Preview from Scott Guthrie’s site. With that installed, fire up VS 2K5, go to File | New | Project… Enter “Web” for the name, “TestApp” for the solution name and pick a location of your choice as seen on this screenshot:

Choosing the web application template

What’s odd is there’s a solution file on your disk, but the Visual Studio Project Explorer is not showing the solution name:

Web project skeleton

In VS 2K3 you could simply right-click on the solution and add a new Class Library project. It’s a little more confusing here.

Go to File | New | Project… again. Select the Class Library template. Enter “DataAccess” for the name, and make sure you select “Add to Solution” below!

Add a class library to the project to serve as a data access layer

This time the solution name is visible and the project is shaping up nicely! Like in old days, you can right-click it and choose Add | New Project… right there.

You can see the solution now and add projects the old way 

Keep adding other class libraries as necessary.

Wait, It Works With Web Sites Too!

Ironically, you can do something similar with a vanilla Web Site project, except that your directory structure may get convoluted and the solution file will end up under My Documents\Visual Studio 2005\Projects.

Comments

Comment permalink 1 Daniel Steigerwald |
I don't see any reason for using Web Application Project, except better control over files existing in project.
The title of article is a little bit a misleading. I excepted something about taming layers, assemblies and project dependecies in Visual Studio Solutions. Eternal problem :)
App_Code is very useful. Every code that IS related to web application (base page classes, global constants, etc) and is NOT related to concrete page should be placed there.
Yes, default storing of solution files in THE OTHER place than project directory is a bit confusing.
Comment permalink 2 Mads Foersom |
Go to Options > Projects and Solutions, and then check "Always show solution" ;-)
Comment permalink 3 Milan Negovan |
Aaaah, nice! Thank you, Mads!
Comment permalink 4 Simone Busoli |
Is this a tutorial about creating a multi tiered app? Looks to me just like a tutorial about creating two projects with Visual Studio!
Comment permalink 5 Milan Negovan |
No, the word tutorial is not mentioned anywhere. It's a post about a workaround. A tutorial on how to build a multi-tiered app would be much much longer.

Emails and Notifications

Would you like to be notified when somebody responds to this post?  Would you like to have these comments emailed to you?

Submit your comment

Please enter only text since all HTML tags except hyperlinks will be stripped. Hyperlinks will become live links. Any comments with flaming or offensive language will be deleted. Be courteous to other posters. Thank you.

Your name (required):
Your email (optional):
Your site's URL (optional):
Enter this number
Type in the number above:
Comment (required):