Cookiemanager (C#)
Posted by Sem Dendoncker on June 11th, 2010Hello,
In many of my applications I need to transfer the data from one page to another.
I used to do this by using a session but the thing with sessions is that they are unreliable.
You never know when they will disappear. There are several possibilities that a session can disappear (session timeout, application needs more memory, …).
The I thought about another way to do this. Then I thought why not using encrypted querystrings but that idea was countered real hard on stackoverflow.com (http://stackoverflow.com/questions/2989703/how-can-you-secure-encrypt-your-querystring-in-asp-net).
Finally I used one of the suggested solutions, why not putting your essential data into a cookie.
Therefore I’ve created an object called “CookieManager”.
Basically it works as a dictionary that contains all the properties you like/want.
You can add/remove properties (with their values) very easely.
This is the code to add a property
CookieManager manager = new CookieManager(cookieName, true); manager.SetPropertyValue(property, value)
This is the code to get the value of a property
CookieManager manager = new CookieManager(cookieName, true); manager.GetPropertyValue(property);
This is the code to remove a property
CookieManager manager = new CookieManager(cookieName, true); manager.RemoveProperty(property);
Easy no?
I’m still working on a full manual for the manager, but the object is so easy to use anyone could use it.
For the ones who would like to have the sourcecode, just leave a comment and I’ll email it to you.
Cheers,
M.
Recent Comments