简体   繁体   English

ASP.NET MVC for MONO中的只读会话状态

[英]Readonly session state in ASP.NET MVC for MONO

I've been using MVC 5 with master branch of mono and I suspect mono that there's missing implementation for following attribute: 我一直在将MVC 5与mono的主分支一起使用,我怀疑mono缺少以下属性的实现:

[SessionState(SessionStateBehavior.ReadOnly)]

I tried to decorate selected two controllers with the attribute and Thread.Sleep (5000). 我试图用attribute和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). 为了提供完整的信息,我一直在使用mod_mono(也是master分支)。

Do you have experiences with parallel execution for a single session? 您是否有一个会话并行执行的经验?

Thanks! 谢谢!

Please check references to: https://github.com/mono/mono/blob/effa4c07ba850bedbe1ff54b2a5df281c058ebcb/mcs/class/System.Web/System.Web.SessionState_2.0/SessionStateBehavior.cs 请检查对以下内容的引用: 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. 请注意,某些Web服务器(例如apache)在某些情况下可能会阻止来自同一用户的并发请求,而不是图像。 If that is your case, let me know to provide you more details. 如果您的情况如此,请告知我们,以提供更多详细信息。

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). 我在使用fastcgi-mono-server4 + nginx和独立使用xsp4时遇到了相同的问题,所以我得出结论,在此版本的mono(debian发行版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. 我解决了在web.config中设置<sessionState mode="Off" /> ,并使用System.Runtime.Caching.MemoryCache处理服务器端的会话,该会话由GUID(用于会话ID仿真)和实际的字符串。

To set the cookie I wrote this override in my controller base class 要设置cookie,我在控制器基类中编写了此覆盖

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 我添加了一个小助手来获取相同基类中的会话ID

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. 这解决了我在Mono上的问题,我确实需要来自同一会话的并发连接,并且我需要保持每个会话的状态值,但是您的里程可能会有所不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM