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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With