July 2006 - Posts

Displaying a Breadcrumb in the Page's Title
20 July 06 06:31 PM | Scott Mitchell

ASP.NET 2.0 site navigation features includes a breadcrumb web control (SiteMapPath) that, when added to a page that exists within the site map, displays output like:

Home > Products > Books > Fiction

Where the nodes in the breadcumb are links back to the respective sections. Internally, the SiteMapPath control finds the current site map node being visited and walks up the site map to the root, generating the output. The SiteMapPath is great for displaying a breadcrumb as text in a web page, but wouldn't it be nice to have the web page's title automatically set to the same breadcrumb text? (The page's title is what appears in the browser's title bar and is the default text used when bookmarking a page.)

It's really quite easy to add this functionality to your site. The site map's structure and data can be accessed programmatically via the SiteMap class. If you're using a master page, you can just drop the following code in the Page_Load event handler, otherwise you'll need to add this on a page-by-page basis:

1 // put the "default" title here

2 string title = "Welcome to My Website!";

3

4 if (SiteMap.CurrentNode != null)

5 {

6 SiteMapNode current = SiteMap.CurrentNode;

7 title = current.Title;

8 current = current.ParentNode;

9

10 while (current != null)

11 {

12 title = string.Concat(current.Title, " :: ", title);

13 current = current.ParentNode;

14 }

15 }

16

17 // finally, set the page's title to the title variable

18 Page.Title = title;

That's all there is to it! Initialize the title variable to the value you want displayed if the currently requested page is not in the site map. To set the page's title, simply use Page.Title (see Dynamically Setting the Page's Title in ASP.NET 2.0 for more info).

The tutorials in my Working with Data in ASP.NET 2.0 series just leave the pages' titles set to “Untitled Page“. In hindsight, I wish I would have added the above code snippet into the master page in the Master Pages and Site Navigation tutorial, so instead of seeing “Untitled Page“ we'd see something like:

For more information on ASP.NET 2.0's site navigation system, check out my multi-part series on 4Guys, Examining ASP.NET 2.0's Site Navigation.

Filed under:
The Next Batch of "Working with Data in ASP.NET 2.0" Tutorials are Online!
13 July 06 07:19 AM | Scott Mitchell

Eight new “Working with Data in ASP.NET 2.0” Tutorials are now available online at www.asp.net. These new eight tutorials show how to edit, insert, and delete data in the GridView, DetailsView, and FormView controls using the ObjectDataSource and tiered architecture examined in the previous tutorials.

  • An Overview of Inserting, Updating, and Deleting Data
  • Examining the Events Associated with Inserting, Updating, and Deleting
  • Handling BLL- and DAL-Level Exceptions in an ASP.NET Page
  • Adding Validation Controls to the Editing and Inserting Interfaces
  • Customizing the Data Modification Interface
  • Implementing Optimistic Concurrency
  • Adding Client-Side Confirmation When Deleting
  • Limiting Data Modification Functionality Based on the User

Like the previous 15, each tutorial is available in both a C# and VB version, can have its entire code downloaded as a self-extracting ZIP file, and can be downloaded as a PDF for offline viewing.

Check 'em all out - http://www.asp.net/Learn/DataAccess

Filed under:
An Interview with Patrick Chu from ItsYourTurn.com
11 July 06 04:00 PM | Scott Mitchell

ItsYourTurn.com is a play-by-play game website that I was turned onto several years ago by a colleague. Since I joined the free site in October 4th, 2002, I've played 2,286 games (although I'm sure you'll be delighted to know I've won 58.7% of the games I've played).

ItsYourTurn.com (IYT) runs on the Microsoft web stack - ASP.NET 2.0, SQL Server 2005, IIS 6.0 - and is run, full time, by Patrick Chu, two other developers, and a part time support staff. IYT has over 2.5 million registered accounts, a database with over 470 million active records, and records around four million page views per day.

Recently I interviewed Patrick, asking an array of technological and business-related questions. Patrick provided very in-depth and thought out answers, including information on IYT's hardware and hosting configuration, the motivation and rationale behind starting this business, his thoughts on AJAX, life during the dot com bubble, and his views on the future of web development.

You can read the interview on 4Guys, at A Conversation with Patrick Chu.

Enjoy!

August's Toolbox Column in MSDN Magazine
07 July 06 01:36 PM | Scott Mitchell

My eighth Toolbox column in the August 2006 issue of MSDN Magazine is now avaiable online. The August issue examines three products:

  • Red-Gate Software's SQL Data Compare (version 5) - allows the data within two schema-identical databases to be compared and synchronized; very useful if you have a test and production database whose underlying data you want to sync (for example, pulling back the live data back to the test database for some 'real world' testing)
  • Error Logging Modules and Handlers (ELMAH) - a free, open-source collection of HTTP Modules and Handlers created by Atif Aziz for automatically logging unhandled exceptions and providing UIs for displaying the error log. ELMAH is the first thing I add to all of my new ASP.NET projects... [See this blog entry for more information...]
  • Sky Software's Shell MegaPack (version 7.1) - Shell MegaPack includes a series of ActiveX and .NET controls for providing the native Windows Explorer shell experience in a WinForms application.

Due to space limitations, this issue of the Toolbox column does not include a book review; it's been pushed to the September 2006 issue (sorry, I am just too verbose).

As always, if you have any suggestions for products or books to review for the Toolbox column, please send them into toolsmm@microsoft.com

You can keep abreast of the latest Toolbox articles through the column's RSS feed or the Toolbox column category here on my blog.

Filed under:
Giving a CAPTCHA a Whirl
06 July 06 05:17 PM | Scott Mitchell

Comment spam is evil. I've been getting on the tune of 25-50 comment spams per day the past several weeks. My custom utility to quickly delete comments in .Text has helped delete comment spams after the fact; additionally, SQL triggers have, to date, proactively nuked over 20,700 comment spams (although they have also stopped valid posters who have added common spam 'keywords' to their posts).

Since the SQL triggers are clearly no longer working, I'm going to give CAPTCHAs a try. In theory, CAPTCHAs can be broken... easily. However, I'm hoping/assuming that the vast majority of scum known as comment spammers aren't using programs that can decode CAPTCHAs and aren't using the social engineering/free pr0n!! techniques detailed here. Rather, I'm assuming a scant few of the comment spams (the ones I get like one or two of a day) are entered by actual humans; the majority, of which I get a blast of, say, 30 in a five second period, are probably coming from a pretty dumb HTTP screen scraping/HTTP posting program. If my assumptions are sound, then the CAPTCHA ought to drastically reduce the amount of comment spam appearing on my blog.

I've taken down my comment spam-related triggers and replaced them with Miguel Jimenez's free Clearscreen SharpHIP CAPTCHA Control. The nice thing about this control is that it automatically checks for validity on postback so it integrates with .Text without having to modify the codebase. One downside, however, is that any other postback sections on the web page will no longer work unless the CAPTCHA is filled out (you may have noticed the blog entry rating feature has been removed).

Hopefully the CAPTCHA cuts down on the comment spam, as having to wade through and delete 50+ comments every day or two is really started to get mundane and annoying. (I do take removing comment spam seriously, though. I challenge you to find a single piece of irrefutable spam in one of my blog entries that's older than, say, a week.)

My Blog's Three Year Anniversary
04 July 06 12:35 PM | Scott Mitchell

Holy cripes, over the weekend my blog turned three years old! This whole mess started back on July 2nd, 2003, when I posted the following immortal words:

Ok, so I decided to jump onto the "blog bandwagon" and create my own blog. I am such a tool.

I feel so old. It really is amazing how fast time seems to pass by.....

Anywho, some exciting news - I've got a cool interview with Patrick Chu, found of ItsYourTurn.com, that I'll be posting here sometime in the next week or so. ItsYourTurn.com is a turn-by-turn game site that I've lost untold hours at over the years playing (primarily) chess and Stack4x4. ItsYourTurn.com is powered by the “Microsoft stack” (custom ISAPI, ASP.NET 2.0, SQL Server, etc.) and has a fair share of load - ~700,000 game moves every day and a database with over 470 million records. The interview has some great technical tidbits and advice along with a view from the inside of a small company (two full-time programmers and a part-time support staff member).

Filed under:
More Posts

Archives

My Books

  • Teach Yourself ASP.NET 4 in 24 Hours
  • Teach Yourself ASP.NET 3.5 in 24 Hours
  • Teach Yourself ASP.NET 2.0 in 24 Hours
  • ASP.NET Data Web Controls Kick Start
  • ASP.NET: Tips, Tutorials, and Code
  • Designing Active Server Pages
  • Teach Yourself Active Server Pages 3.0 in 21 Days

I am a Microsoft MVP for ASP.NET.

I am an ASPInsider.