c# - IIS/.Net 只允许对给定用户 session 的单个并发响应

标签 c# asp.net .net session iis

这是我的问题:

我们有一个 .Net 4.5 Web 表单应用程序。由于服务器端的大量数据访问和操作,应用程序中的某些页面需要很长时间才能加载。如果用户在页面加载完成之前关闭浏览器选项卡,然后打开一个新选项卡,则对新选项卡中的应用程序的任何请求都将挂起 20 分钟或更长时间,或者只是超时。但是,如果他们打开一个新的隐身窗口 (Chrome) 或其他浏览器,他们可以立即连接。

我相信这是因为 .Net 按顺序处理来自同一 session 的并发请求,如下所述:ASP.NET Session State Overview

Concurrent Requests and Session State Access to ASP.NET session state is exclusive per session, which means that if two different users make concurrent requests, access to each separate session is granted concurrently. However, if two concurrent requests are made for the same session (by using the same SessionID value), the first request gets exclusive access to the session information. The second request executes only after the first request is finished. (The second session can also get access if the exclusive lock on the information is freed because the first request exceeds the lock time-out.) If the EnableSessionState value in the @ Page directive is set to ReadOnly, a request for the read-only session information does not result in an exclusive lock on the session data. However, read-only requests for session data might still have to wait for a lock set by a read-write request for session data to clear.

我在研究这个问题时发现的一些帖子暗示(但未证实)当浏览器选项卡在响应完成之前关闭时, session 会“卡住”并且不会响应来自同一 session 的新请求直到设置的 SessionTimeout 时间段结束。我假设来自隐身窗口的请求被接受是因为它有一个新 session 。

除了等待超时之外,有谁知道有什么方法可以释放 session 来处理新请求吗?有什么方法可以检测到客户端不再收听了吗?我找到了 Response.IsClientConnected,这看起来很有希望,但我不确定它会如何使用。

注意:这是一个包含大量业务逻辑的遗留应用程序,目前的情况不允许在此时重新编写的时间或预算。因此,“只重写页面以使其加载速度更快”的建议并不是立即可行的,尽管我承认这确实是最好的解决方案。

最佳答案

我自己在并发性和 session 状态方面也有类似的问题。

尝试在您的 web.config 中设置 enableSessionState="ReadOnly"。

在这里查看我的想法:EnableSessionState = ReadOnly - possible side effects?

编辑:抱歉,看到您可能已经尝试过这样做了。

关于c# - IIS/.Net 只允许对给定用户 session 的单个并发响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24494833/

相关文章:

c# - MSTest 超时属性未按预期工作

C#:如何声明多个相似的结构?

c# - 尝试从 flatbuffer 的二进制文件访问 "LengthofTable"时出现 SystemAccessOutOfbound 异常

c# - 一个例程/函数中的 CSV 解析器?

asp.net - PayPal IPN 和 PDT 混合

javascript - 带有参数的 AJAX 调用不起作用

c# - '='字符,十六进制值0x3D,不能包含在名称中

.net - 如何设计一个 ASP.NET MVC 站点以使用 Velocity 进行缓存?

c# - 如何 'not' Entity Framework 的 lambda 表达式

c# - 网络应用设计