Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://codingsmith.co.za/a-better-way-of-working-with-httpcontext-session-in-mvc/" rel="nofollow">http://codingsmith.co.za/a-better-way-of-working-with-httpcontext-session-in-mvc/</a> (apologies for the colours on my blog was tooling around with themes and just havent fixed it yet)</p> <pre><code>public interface ISessionCache { T Get&lt;T&gt;(string key); void Set&lt;T&gt;(string key, T item); bool contains(string key); void clearKey(string key); T singleTon&lt;T&gt;(String key, getStuffAction&lt;T&gt; actionToPerform); } public class InMemorySessionCache : BaseSessionCache { Dictionary&lt;String, Object&gt; _col; public InMemorySessionCache() { _col = new Dictionary&lt;string, object&gt;(); } public T Get&lt;T&gt;(string key) { return (T)_col[key]; } public void Set&lt;T&gt;(string key, T item) { _col.Add(key, item); } public bool contains(string key) { if (_col.ContainsKey(key)) { return true; } return false; } public void clearKey(string key) { if (contains(key)) { _col.Remove(key); } } } public class HttpContextSessionCache : BaseSessionCache { private readonly HttpContext _context; public HttpContextSessionCache() { _context = HttpContext.Current; } public T Get&lt;T&gt;(string key) { object value = _context.Session[key]; return value == null ? default(T) : (T)value; } public void Set&lt;T&gt;(string key, T item) { _context.Session[key] = item; } public bool contains(string key) { if (_context.Session[key] != null) { return true; } return false; } public void clearKey(string key) { _context.Session[key] = null; } } </code></pre> <p>i came up with that a few years ago and it works fine. same basic idea as everyone else i guess, why microsoft dont just implement this as standard eludes me. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload