www.cnauroth.net
This article will change as the site evolves. If I implement a major new feature or rearchitect anything, then I'll document it here.
www.cnauroth.net is an ASP.NET application built using Microsoft Visual Web Developer 2005 Express Edition. In some cases, I make use of .NET Framework 2.0 features, such as the GridView control.
Site Navigation
My team at Amazon.com owns the code that generates the top navigation bar on the site. At first glance, it's not a complicated feature. We just need to render a bit of HTML with some hyperlinks on every page of the site. When you click around the site, you might start to see why it's more complicated than that. The product category links remain the same on every page of the site, but additional links in a sub-navigation bar will change depending on your current location in the site. If one of the sub-navigation links is currently selected, then it needs to be rendered slightly differently. The available options in the search dropdown also change.
A personal website certainly isn't as complex as Amazon.com, but I quickly encountered some of the same issues in dealing with site navigation. My requirements were:
- A standard set of navigation links should display at the top of each page.
- The currently selected link should render different HTML. Specifically, it shouldn't even render as a hyperlink, since a hyperlink wouldn't add any value for the user.
- If the specific links need to be changed in the future, then changing the information in one place should reflect the changes throughout all pages on the site.
The user interface requirements came into place quickly in the form of a UserControl that I could include on any page with just a few lines of code in the .aspx file. To satisfy the data requirements, I decided that the configuration of the site navigation links should be centralized in the web.config file, like this:
<topNavMenu>
<items>
<item displayName="Welcome" navigateUrl="~/Default.aspx" imageUrl="~/Images/home_16.gif" />
<item displayName="About&nbsp;Me" navigateUrl="~/AboutMe.aspx" imageUrl="~/Images/folder-open_16.gif" />
<item displayName="Diary" navigateUrl="~/Diary.aspx" imageUrl="~/Images/documents_16.gif" />
<item displayName="Software" navigateUrl="~/Software/Default.aspx" imageUrl="~/Images/save_16.gif" />
<item displayName="Downloads" navigateUrl="~/Downloads.aspx" imageUrl="~/Images/arrow-down_16.gif" />
<item displayName="About&nbsp;the&nbsp;Site" navigateUrl="~/AboutTheSite.aspx" imageUrl="~/Images/computer_16.gif" />
</items>
</topNavMenu>
I then implemented an IConfigurationSectionHandler to parse this information from the configuration and return it as an object to the UserControl. An ASP .NET DataList control is data-bound to this collection of configuration information to create the final user interface. There was a small difficulty that I hadn't anticipated in dealing with the application virtual root directory, which is different in my development environment than in my hosting environment. Fotunately, ASP .NET 2.0 allows path specifications in server-side controls to use the ~ character to represent the application virtual root directory.
This approach turned out to be flexible enough that I reused it in creating the left navigation menu on the Software section of the site. I just used a separate configuration section to represent that menu, and I drove the information into another UserControl.
Diary
The diary feature requires handling of dynamic content far more than any other feature of the site. These were my requirements:
- Since diary entries could occur daily, creating a new diary entry should be fast and easy.
- Users should be able to navigate quickly between various diary entries.
- At the time of site development, the final hosting environment of the site is unknown, so no assumption can be made that a particular database or other persistence technology will be available.
- In the future, it would be nice to have a Windows Forms application to facilitate creation of diary content which could then be uploaded to the site.
Based on these requirements, I chose XML files as the persistence mechanism for diary entries. For efficient access, I chose to implement a DiaryIndex object. At application startup, this object traverses all of the XML files present in a dedicated directory. It pulls basic information, such as title and date, from each XML file, and stores the information in a series of Hashtable objects. The DiaryIndex provides efficient answers to queries for diary-related data from the user interface, such as:
- The entry matching a particular ID.
- The entry matching a particular date.
- All entries matching a particular year and month.
The DiaryIndex object is stored in the cache during the first diary page load. Creation of a new diary entry is as simple as creating a new XML file that matches the schema and dropping it into the right directory. At that point, the DiaryIndex object is reconstructed to pick up the new entry.
The user interface combines 2 ASP .NET controls, Calendar and GridView, to implement navigation through the diary data.