This post originated from an RSS feed registered with .NET Buzz
by Scott Watermasysk.
Original Post: HttpContext.Current
Feed Title: ScottW's ASP.NET WebLog
Feed URL: /error.aspx?aspxerrorpath=/blog/rss.aspx
Feed Description: ASP.NET and Blogging
Oddur Magnussonwrote that he recently found HttpContext.Current and was about to refactor his code, so that he did not need to pass in the current Context as a parameter.
While this will work, using a simple overload can give you both the flexibility of not having to pass in the current context if it is not readily available as well as a performance gain for being able to use a current HttpContext reference when it is available.
Here is a quick example of grabbing an item from the Context.Items collection.
publicstring GetValue(HttpContext Context)
{
return Context.Items[key] as string;
}