Software Ninja

The Software Ninja is a professional software developer. Here are some books I find interesting and useful.

My Photo
Name: Matt Smith
Location: Utah, United States

While continuing to provide for his family as a computer programmer, Matt has been studying marriage and relationships for many years. He is the author of the soon to be released book: Ferocious Flirting: Making Marriage Wonderful. He is also available for speaking to groups on keeping the romance going in marriage. Feel free to email me with comments, questions or suggestions.

Friday, September 28, 2007

ASP.NET caching based on a cookie

You have to use VaryByCustom parameter. Your OutputCache directive will look like this

<%@ OutputCache Duration="600" VaryByCustom="StyleSheet" %>

and you have declare the following method in which we access the Cookie and pass the value back

 
public override string GetVaryByCustomString(System.Web.HttpContext context, string custom) {
if (custom == "StyleSheet"){
return "StyleSheet=" + this.Request.Cookies["StyleSheet"];
}
}



Given this method, you should be able to cache based not only on cookies, but any other string value or anything that can be converted into a string.

0 Comments:

Post a Comment

<< Home