Jon Flanders' Blog

Problem with the ETag code in my book

Wednesday, March 18, 2009 3:53:38 PM (GMT Standard Time, UTC+00:00)

I just discovered that in Chapter 11 - my code for generating ETags has a bug.  The code needs to wrap the ETag in a set of quotes:

string GenerateETag(User u)
{
    byte[] bytes = Encoding.UTF8.GetBytes(u.UserId + u.LastModified.ToString());
    byte[] hash = MD5.Create().ComputeHash(bytes);
    string etag = Convert.ToBase64String(hash);
    return string.Format("\"{0}\"", etag);
}
Sorry - as I always say "Hi - I'm Jon, I'm a developer, and I write code with bugs" ;)

  #    Comments [0]   

All comments require the approval of the site owner before being displayed.
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview