I have just begun working on an application, a website which offers people paid subscriptions
via PayPal to a weekly message, which they can view on the site after logging in. I had the
site designed, including the CSS and two separate master pages. The site was up on staging
as an ASP.NET 2.0 Web Application Project written in C#, and I had just started looking to
the required functionality when I got an unexpected lesson in the differences between the
two ASP.NET development models; that is, the "Web Site" and the "Web Application Project"
models.
Quick note on naming conventions: I always use the single-word version, "website"; personal choice. Microsoft
refers to the ASP.NET template as "Web Site", as in FILE -> New Web Site. Still, if you look
at the Drop Down Menu names in Visual Studio after opting to go with a "Web Site", you will
see "Website". Worse still, try googling this! Consistency aside, this is one dumb-ass
naming choice which is right up there with MOSS "Features", another joy to Google... end of rant ;-)
I normally use the Web Application Project model because it is what I am used to and it
makes sense to me. I have always viewed the Web Site model as something to use for
demonstration purposes and the like. Truthfully, when Microsoft initially brought out only
the Web Site template with VS 2005 and then did the turnaround to also include the Web
Application Project template in SP1, I believe that at this point they should have dropped
the Web Site model completely. To this day, it leads to nothing but confusion among
developers of all levels.
The differences between the two models have been pretty well covered, or at least so I
thought. This article is not going to delve into the details of these templates, so for the benefit of those new to ASP.NET, here are some informative references on the two models:
* Comparing Web Site Projects and Web Application Projects
* Visual Studio 2005 Web Application Project Option
* ASP.NET 2.0 - Web Site vs Web Application
* Converting a Web Site Project to a Web Application Project
* Add a Reference to a Visual Studio Project in a Web Site
With a two-week deadline, I wanted as much
out-of-the-box functionality as I could leverage from ASP.NET.
Surprise #1: Profiles only Work Out-of-the-Box with the Web Site Template
In order to implement the logic for the application described above, I planned on using
User Profiles to store some extra information for each subscriber such as the date they
subscribed along with the type of subscription. Profiles allow you to store some extra
information per user when using the ASP.NET membership system. In this case, I was using
SQL Server 2005 to store membership details. Profiles are stored in the database
automatically and all we have to do is add this extra information to our web.config file. We don't need to know anything about how this data is stored or retrieved.
What they don't tell you is that Profiles only work out-of-the-box with the Web Site option. I discovered this while reading the comments on Scott Guthrie's great blog posting on this topic. There is a workaround available and you can find out more about that here. The problem stems from the fact the Web Application Project does not have the Profile object automatically added to each page as with the Web Site project, so we cannot get
strongly-typed programmatic access to the profile properties defined in our web.config
file.
The Web Project workaround did not appeal to me because this is an E-Commerce site
for a client and I did not like the idea of having to resort to an add-in. I had no way of
knowing how stable this was or what other issues might have arisen within my short project
time-frame. You can code your own custom profile class if you choose.
The real kicker here is that Profiles are still not available out-of-the-box with the VS 2008 ASP.NET 3.5 Web Application Project template. A mysterious ommission...
Surprise #2: Where is the Web Content Form in the Web Site Project?
As already mentioned, I was using two separate master pages and every page in my site is based off one of these master pages. When I went to add a Web Content Form in the Web Site "project", there was none! At first I hand-coded the page tag, then I noticed the "Select
master page" checkbox. The images below show the Web Content Form when using a Web
Application Project and the lack of one when using the Web Site "Project".
Surprise #3: Where have all the Namespaces Gone?
No namespaces are used for classes anywhere in the App_Code folder. Now, most of us already
know that the application automagically finds classes placed in this folder. But, for
someone like me who is so used to working with the project model, this didn't strike me
right off the bat! So, presumably name conflicts are not a cause for concern here? This is
confirmation that Microsoft never intended the Web Site "Project" template for enterprise work, if
anyone was ever in any doubt.
My own project will have a user control which is referenced from a master page. On reading
this post by Rick Strahl, I see that there are all kinds of difficulties when accessing
user controls with the Web Site model - read through the comments. Now I'm thinking that I
may revert to the Web Application Project and use the Web Profile Builder to solve my
Profile issues after all! At least I won't have grapple with trying to dynamically load a user
control from a different assembly... are you getting the bad code smell yet?