Cool Dude Programmer 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 omission...

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".

Web Application Project - Web Content Form

 

Web Site Project - No Web Content Form

 

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?

kick it on DotNetKicks.com   PHP, ASP, .NET, JSP Resources, Reviews



New MSDN Code Gallery

by agrace 3. March 2008 13:04

Are you looking for some free code samples? Microsoft recently launched the MSDN Code Gallery. It differs from the CodePlex site in that it is more geared towards developers who are starting out. It is a true community site where you can create your own resources page in the shape of a wiki and share your own code samples with the community. You can keep it in edit mode for 30 days before sharing your code masterpieces with an unsuspecting public ;-)

I had a surf around the new site and came up with a gem of a new tool for Visual Studio 2008. It's called StickyNotes and it is a Visual Studio package that provides sticky notes capabilities to project and project items inside Visual Studio 2008.

StickyNotes

This is so much neater than the standard Task List that comes with VS, although I can see myself using both. StickyNotes is ideal for jotting down reminders of things to do at a file level. I usually load my code pages with comments in the early stages of a project and this tool is sure to free up my code files. Thanks to Pablo Galiano for this wonderful new tool :-)

kick it on DotNetKicks.com




Guest Book Solution You can also view part I of this article which describes the setting up of this application with Visual Studio 2008 and IIS 7, running on Vista. SQL Server 2005 was used as the database. I had originally blogged on this using VS 2005 but feedback indicated that quite a few people are now using VS 2008, so I upgraded it to VS 2008, which I am currently running on VMWare Workstation... the best $190 I ever spent. This is part II and the full code will be available for download in part III, real soon!

Speaking of feedback, I have been having problems with the comments system on this blog for some time now. So, pretty soon I am upgrading the blog engine and switching to a database version. The plan is to eventually make it a real "Community" site. Watch this space...

The Guest Book application is written in C# and is pretty straightforward. Here I will walk through the creation of the back-end which will allow the site administrator to moderate the comments posted to the guest book by site visitors.

First, we need to set up our membership system. The membership system is where most people seem to get stuck. There are several ways of achieving the same thing and I think that this is what causes much of the confusion. Typically, in an application such as this you would use a CAPTCHA control to combat the spammers, so we are not going to force users to register in order to sign the guest book. We will need an administration area for our admin forms, so we will create an "admin" role. The way I go about this is to create a new folder and call it Admin. Add a config file  to this new folder and set up the authorization rules as shown below.

Admin Web.config

Now, we're going to cheat a little. I'm going to do the TV chef and slip in a little something I pre-prepared earlier in the kitchen (actually gleaned from several of Scott Guthrie's blog postings). I always keep a sample Web.config file handy that I know is set up correctly for a basic membership system. I start this way rather than jumping in right off with the WSAT wizard because I want to have one single database for both my application and membership data. Tidier. So, I manually set up the database connection in the project Web.config file, along with entries for the membership and authentication sections. See the snippets below, and don't forget to include the roleManager tag!

Project Web.config

Now that the membership database connection is configured the way we want it, we can run the aspnet_regsql tool from the command line. This will create the actual membership database objects for us as part of our Guests database. Just navigate from the start menu to SQL Server Management Studio and locate the command line tool under the Configuration Tools folder. Simply enter aspnet_regsql at the prompt and you will be presented with the SQL Server Setup Wizard. Here are some screenshots showing the correct selections to make:

SQL Server Setup Wizard

SQL Server Setup Wizard

SQL Server Setup Wizard

If you go to SSMS and refresh the database, you should now be able to expand the tables icon, and you will see that the wizard had created everything we need for our membership system. At this stage, you are ready to run the WSAT tool and start setting up the admin role and adding the admin user. I will outline this process in the final installment, as well as the creation of our administration forms. Stay tuned!

Membership Database Objects

kick it on DotNetKicks.com   PHP, ASP, .NET, JSP Resources, Reviews