title: Writing to a session variable with SessionStateBehavior.ReadOnly
body: <p>In my ASP.NET MVC 5 application, I'm performing a <code>GET</code> request on a method inside a controller that needs to read a value stored in session. To avoid session state locking issue, I've set <code>SessionStateBehavior</code> to <code>ReadOnly</code> on the class level. </p>
  
  <pre><code> [SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)]
      public class TestController: Controller
      {
           var test = Session["KEY"];
  ...
  </code></pre>
  
  <p>However, very occasionally, I need to overwrite the <code>Session</code> variable to something else inside that same method. ASP.NET MVC does not allow me to do this with <code>SessionStateBehavior</code> set to <code>ReadOnly</code>. I can't set it to <code>Required</code> because then I run into the issue of session state locking issue again, preventing concurrent AJAX requests.</p>
  
  <p>What's a good solution for this?</p>
  
  <p>Edit: We're using SQL server for session state management.</p>