Note that there are some explanatory texts on larger screens.

plurals
  1. POReplacing ASP.Net's session entirely
    text
    copied!<p>ASP.Net session appear perfect for a traditional WebForms app, but they do some things that are a serious problem for a modern AJAX and MVC application.</p> <p>Specifically there are only 3 ways to access the ASP.Net provider:</p> <ol> <li><p><strong>Locking read &amp; write</strong> (default) - the session is locked from <code>AcquireRequestState</code> firing until <code>ReleaseRequestState</code> fires. If 3 requests occur from the browser at once they'll queue up on the server. This is the only option in MVC 2, but MVC 3 allows...</p></li> <li><p><strong>Non-locking read only</strong> - the session isn't locked, but can't be saved to. This appears to be <a href="https://stackoverflow.com/questions/8939188">unreliable though</a>, as some reads appear to lock the session again.</p></li> <li><p><strong>Session disabled</strong> - any attempt to read or write to the session throws an exception.</p></li> </ol> <p>However with a modern MVC app I have lots of AJAX events happening at once - I don't want them the queue on the server but I do want them to be able to write to the session.</p> <p>What I want is a fourth mode: <strong>Dirty read, last write wins</strong></p> <p>I think (happy to be corrected) that the only way to do this is to completely replace ASP.Net's sessions. I can write my <a href="http://msdn.microsoft.com/en-us/library/ms178587.aspx" rel="nofollow noreferrer">own provider</a>, but ASP will still call it with one of the 3 patters it supports. Is there any way to make ASP.Net support optimistic concurrency?</p> <p>This leaves me replacing all calls to the session with a new class that basically does the same thing, but doesn't lock - which is a pain.</p> <p>I want to keep as much of the current session stuff as I can (most significantly session IDs in various logs) with the minimum amount of code replacement. Is there any way to do this? Ideally I'd want <code>HttpContext.Current.Session</code> to point to my new class but without ASP.Net locking any requests.</p> <p>Has anyone already done something like this? It seems odd that with all the AJAXey MVC apps out there this is a new problem with ASP.</p>
 

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