Cookie wrapper in MVC4 c#
I'd like to create a cookie wrapper in my application to help support a
DRY approach to coding common cookie methods, provide intellisense for
cookie-type properties (keys), and protect against typo-errors when
working with cookies from multiple classes and namespaces.
The best structure for this (that I can think of) is to apply a base class
like such:
abstract class CookieBase{
protected HttpRequestBase request;
protected HttpCookie cookie;
protected string name;
public HttpCookie Cookie { }
public string Name { get; }
public HttpCookie Get(){ ... }
protected string GetValue(string key){ ... }
public bool IsSet(){ ... }
protected void SetValue(string key, string value){ ... }
}
Then for each cookie-type that inherits the base class define properties
for each key that should be stored in the HttpCookie, and define a
constructor that accepts the Request object as a parameter and
instantiates the Cookie property of the base class.
Any ideas on how I might improve this design, or suggestions to
alternative approaches to attaining the goals I stated at the start of
this post?
No comments:
Post a Comment