ASP.NET Duplicate Cookies - 8/8/2009

One of my favorite books is Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries (2nd Edition) which I re-read twice a year to remind myself what is better or worse.

The book points out that:

  • Hindsight is 20/20
  • Designing based on use cases and making the most common usecases the most obvious to is a good thing

That being said, I'd like to complain about the cookies collection in ASP.NET. It exposes two methods .Add and .Set, if you have an existing cookie whose values you modified and you call .Add you get a duplicate. 99% of the time, this is not the desirable outcome.

Instead deprecating those members in favor of

  • .SafeAdd(cookie)
  • .SafeAdd(cookie, allowDuplicates)
would be much more useful.

Lo, and behold my friend James has a nice extension method.

Blog ID: 2009 08-08_Blog_119