Search code examples
httpcontextitemstype-safety

Type-safe alternative to HttpContext.Items


I am implementing an HTTP Module in ASP.NET to identify geographical information based on the request's IP (a GeoIP module) and I will need to place things somewhere so the handler or later modules can inspect.

Except HttpContext.Items (which is not type-safe) is there some other decent alternative?


Solution

  • It depends what you want to store. Type safety can only really apply if you are using one type of item within a collection so none of the generic stores will be applicable for you.

    Maybe it would be a better idea to implement a helper class to write and read from a subset of HttpContext.Current.Items in a type safe manner?