Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing to a session variable with SessionStateBehavior.ReadOnly

Tags:

In my ASP.NET MVC 5 application, I'm performing a GET 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 SessionStateBehavior to ReadOnly on the class level.

 [SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)]
    public class TestController: Controller
    {
         var test = Session["KEY"];
...

However, very occasionally, I need to overwrite the Session variable to something else inside that same method. ASP.NET MVC does not allow me to do this with SessionStateBehavior set to ReadOnly. I can't set it to Required because then I run into the issue of session state locking issue again, preventing concurrent AJAX requests.

What's a good solution for this?

Edit: We're using SQL server for session state management.