2

I've been using MVC 5 with master branch of mono and I suspect mono that there's missing implementation for following attribute:

[SessionState(SessionStateBehavior.ReadOnly)]

I tried to decorate selected two controllers with the attribute and Thread.Sleep (5000). As results present these two requests were executed sequentially, not as one expect in parallel.

To give a complete information, I've been using mod_mono (also master branch).

Do you have experiences with parallel execution for a single session?

Thanks!

marxin
  • 715
  • 1
  • 10
  • 18
  • Encountered the same problem and this is due to a bug on Mono. I came up with a workaround for that until this is fixed: https://stackoverflow.com/a/72335655/1918287 – Maor Refaeli May 22 '22 at 07:41

2 Answers2

1

I had the same problem, with fastcgi-mono-server4 + nginx and with xsp4 stand-alone, so I concluded that it must be a bug (or some non-implemented feature) in this version of mono (debian distribution 3.8-2).

I worked around the problem setting <sessionState mode="Off" /> in web.config and handling the session on the server side with a System.Runtime.Caching.MemoryCache with keys composed from a GUID (for session ID emulation) and the actual string.

To set the cookie I wrote this override in my controller base class

protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
    if(HttpContext.Request.Cookies["sid"] == null
        && HttpContext.Response.Cookies["sid"] == null) {
        HttpCookie htsid = new HttpCookie("sid", Guid.NewGuid().ToString());
        HttpContext.Response.Cookies.Set(htsid);
    }
    //...
}

and I added a little helper to obtain the session ID in the same base class

internal string sid {
    get {
        HttpCookie htk = HttpContext.Request.Cookies["sid"];
        if(htk == null) {
            htk = HttpContext.Response.Cookies["sid"];
        }

        return htk == null ? null : htk.Value;
    }
}

This solved my problem on Mono, where I do need concurrent connections from the same session and I need to keep state values per-session, but your mileage may vary.

Alex Mazzariol
  • 2,456
  • 1
  • 19
  • 21
0

Please check references to: https://github.com/mono/mono/blob/effa4c07ba850bedbe1ff54b2a5df281c058ebcb/mcs/class/System.Web/System.Web.SessionState_2.0/SessionStateBehavior.cs

Please note that some web servers, like apache, may block a concurrent request from the same user for resources other than images under certain circunstances. If that is your case, let me know to provide you more details.

  • Thats for the reference, I use this enum as attribute. May I ask you how can one debug communication between Apache server and running asp.net server (mod_mono)? I would appreciate more details. – marxin Dec 04 '14 at 20:24