We have just launched an e-commerce site for Australian retailer Myer. I'm very excited about the site and plan to do most of my Christmas shopping there!
The site uses a custom e-commerce engine we developed internally for this project. It is based on the ASP.Net 2.0 and SQL Server 2005 platforms. It also uses quite a lot of client-side stuff to make the shopping experience very slick. The Myer Gifts website - enjoy.
And here are a few helpful "helper" utility methods we've come up with over the last month:
public static class Utilities
{
public static void DisableCache(HttpResponse httpResponse)
{
httpResponse.Cache.SetCacheability(HttpCacheability.NoCache);
httpResponse.Expires = -1;
httpResponse.ClearHeaders();
httpResponse.AppendHeader(@"Cache-Control", @"no-cache"); // HTTP 1.1
httpResponse.AppendHeader(@"Cache-Control", @"private"); // HTTP 1.1
httpResponse.AppendHeader(@"Cache-Control", @"no-store"); // HTTP 1.1
httpResponse.AppendHeader(@"Cache-Control", @"must-revalidate"); // HTTP 1.1
httpResponse.AppendHeader(@"Cache-Control", @"max-stale=0"); // HTTP 1.1
httpResponse.AppendHeader(@"Cache-Control", @"post-check=0"); // HTTP 1.1
httpResponse.AppendHeader(@"Cache-Control", @"pre-check=0"); // HTTP 1.1
httpResponse.AppendHeader(@"Pragma", @"no-cache"); // HTTP 1.1
httpResponse.AppendHeader(@"Keep-Alive", @"timeout=3, max=993"); // HTTP 1.1
httpResponse.AppendHeader(@"Expires", @"Mon, 26 Jul 1997 05:00:00 GMT"); // HTTP 1.1
}
public static void AddMetaTagRobotsNoFollow(Page sourcePage)
{
Utilities.AddMetaTag(sourcePage, @"robots", @"NOFOLLOW");
}
public static void AddMetaTagRobotsNoIndex(Page sourcePage)
{
Utilities.AddMetaTag(sourcePage, @"robots", @"NOINDEX");
}
public static void AddMetaTag(Page sourcePage, string name, string content)
{
HtmlMeta htmlMeta = new HtmlMeta();
htmlMeta.Name = name;
htmlMeta.Content = content;
sourcePage.Header.Controls.Add(htmlMeta);
}
public static string RemoveItemsFromQueryString(NameValueCollection queryString, params string[] itemsToRemove)
{
List<string> items = new List<string>();
foreach (string item in itemsToRemove)
{
items.Add(item.ToLower(CultureInfo.InvariantCulture));
}
string s = string.Empty;
for (int i = 0; i < queryString.Count; i++)
{
if ((queryString.GetKey(i) != null) && !items.Contains(queryString.GetKey(i).ToLower(CultureInfo.InvariantCulture)))
{
s += queryString.GetKey(i) + '=' + queryString[i] + '&';
}
}
return s;
}
public static string GenerateRandomString(int length)
{
// Used for storing the possible characters.
List<char> possibleCharacters = new List<char>();
// Add 0 - 9.
for (int i = 48; i < 58; i++)
{
possibleCharacters.Add((char)i);
}
// Add A - Z.
for (int i = 65; i < 91; i++)
{
possibleCharacters.Add((char)i);
}
// Add a - z.
for (int i = 97; i < 122; i++)
{
possibleCharacters.Add((char)i);
}
Random random = new Random();
string result = string.Empty;
for (int i = 0; i < length; i++)
{
// Get a character out of a random index in the list populated above.
result += possibleCharacters[random.Next(0, possibleCharacters.Count)];
}
return result;
}
}