In every application there are some variables that are set by the ASP.NET application( ASP.NET_SessionId cookie ) and some that are set by the programmer( cached data in Application/Session/Cache/Cookies and so on).
I wanted every time to have a page where I can “clear” / delete those – and not found. So it’s the Clearer project.
It consists of :
- ClearerController with 2 Actions: Index and DeleteItem
- 2 Views : Index.cshtml and EditAppData.cshtml
- Different Models:
- SourceData – enum – can be : None , Application , Cache , Session , Cookies
- AppData - maintains Key/Value and SourceData pairs
- ListAppData – loads data from Application , Cache , Session , Cookies – and deletes.
To make an example, I have put in the Application_Start and Session_Start different values. So the screen is the following:
What I learn from the code:
- The Cookies, Applications, Session , Cache items can be easily converted to an DictionaryEntry and the code can be like this:
DictionaryEntry de = new DictionaryEntry(item, sess[item.ToString()]); AddNew(de, SourceData.Session);
- Code must be error prone – what if some item in Session is null ? So , if I have the Key, all is good:
private void AddNew(DictionaryEntry de, SourceData sd) { AppData ap = new AppData() { source = sd, Key = de.Key.ToString() }; try { var obj = de.Value; ap.Value = (obj == null) ? Null : obj.ToString(); } catch (Exception ex) { ap.Value = string.Format(ErrorToString, ex.Message); } this.Add(ap); } - The dog-food is good: I have followed my advice from msprogrammer.serviciipeweb… and it works ( used for Remove )
[HttpPost] public JsonResult DeleteItem(string TheKey, int Source) { try { var lad = new ListAppData(); lad.DeleteItem(TheKey, (SourceData)Source); return Json(new { ok = true, message = "" }); } catch (Exception ex) { return Json(new { ok = false, message = ex.Message }); } } - When you pass strings in Javascript, there is a simple way to encode: HttpUtility.JavaScriptStringEncode
<a href="javascript:removeItem('@HttpUtility.JavaScriptStringEncode(Model.Key)','@((int)Model.source)','@id')">Remove</a>
Possible uses:
- For developers - when they want to see what happens when a cache item no longer exists
- For developers – to put to site admins some simple tool to reload data from Cache/Application . Just edit the LoadAll function to load only Cache/Application

- For developers – to test easily the session. Just delete ASP.NET_SessionId cookie – you will get another one when you refresh the page.
You can view online at http://clearer.apphb.com/Clearer
The project could be found at http://clearer.codeplex.com and have all – source code, downloadable project .
Next week it will be a Nuget item.
For more features , please leave me a comment here or on codeplex at issues







![clip_image001[4] clip_image001[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0014.jpg)
![clip_image002[4] clip_image002[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0024.jpg)
![clip_image003[4] clip_image003[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0034.jpg)
![clip_image004[4] clip_image004[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0044.jpg)
![clip_image005[4] clip_image005[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0054.jpg)
![clip_image006[4] clip_image006[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0064.jpg)
![clip_image007[4] clip_image007[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0074.jpg)
![clip_image008[4] clip_image008[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0084.jpg)
![clip_image009[4] clip_image009[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0094.jpg)
![clip_image010[4] clip_image010[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0104.jpg)
![clip_image012[4] clip_image012[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0124.jpg)
![clip_image013[4] clip_image013[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0134.jpg)
![clip_image014[4] clip_image014[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0144.jpg)
![clip_image015[4] clip_image015[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0154.jpg)
![clip_image016[4] clip_image016[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0164.jpg)
![clip_image017[4] clip_image017[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0174.jpg)
![clip_image018[4] clip_image018[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0184.jpg)
![clip_image019[4] clip_image019[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0194.jpg)
![clip_image020[4] clip_image020[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0204.jpg)
![clip_image021[4] clip_image021[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0214.jpg)
![clip_image022[4] clip_image022[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0224.jpg)
![clip_image023[4] clip_image023[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0234.jpg)
![clip_image024[4] clip_image024[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0244.jpg)
![clip_image025[4] clip_image025[4]](http://msprogrammer.serviciipeweb.ro/wp-content/uploads/MVC-4_94F/clip_image0254.jpg)