简体   繁体   English

IIS / .Net仅允许对给定用户会话的单个并发响应

[英]IIS / .Net only allows single concurrent response to given user session

Here is my problem: 这是我的问题:

We have a .Net 4.5 web forms application. 我们有一个.Net 4.5 Web表单应用程序。 Some pages in the application take a very long time to load due to heavy data access and manipulation on the server side. 由于服务器端的大量数据访问和操作,应用程序中的某些页面需要很长时间才能加载。 If a user closes their browser tab before the page completes loading, and opens a new tab, any requests to the application in the new tab will hang for 20 minutes or more, or just time out. 如果用户在页面完成加载之前关闭其浏览器选项卡,并打开新选项卡,则新选项卡中对应用程序的任何请求都将挂起20分钟或更长时间,或者只是超时。 However, if they open a new incognito window (Chrome) or another browser, they can connect immediately. 但是,如果他们打开新的隐身窗口(Chrome)或其他浏览器,他们可以立即连接。

I believe this is because .Net handles concurrent requests from the same session sequentially, as explained here: ASP.NET Session State Overview 我相信这是因为.Net按顺序处理来自同一会话的并发请求,如下所述: ASP.NET会话状态概述

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. 并发请求和会话状态对ASP.NET会话状态的访问是每个会话独占的,这意味着如果两个不同的用户发出并发请求,则同时授予对每个单独会话的访问权限。 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. 但是,如果对同一会话发出两个并发请求(通过使用相同的SessionID值),则第一个请求将获得对会话信息的独占访问权。 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. (如果由于第一个请求超过锁定超时而释放信息的独占锁定,则第二个会话也可以访问。)如果@ Page指令中的EnableSessionState值设置为ReadOnly,则只读请求会话信息不会导致会话数据的独占锁定。 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. 但是,会话数据的只读请求可能仍然必须等待由会话数据的读写请求设置的锁定才能清除。

Some posts I've found while researching this issue have alluded to (but not confirmed) that when the browser tab is closed before the response completes, the session gets "stuck" and will not respond to new requests from the same session until the set SessionTimeout period has elapsed. 我在研究这个问题时发现的一些帖子暗示(但未确认)当浏览器选项卡在响应完成之前关闭时,会话“卡住”并且不会响应来自同一会话的新请求直到该集合SessionTimeout期限已过。 It is my hypothesis that a request from an incognito window is accepted because it has a new session. 我的假设是,接受来自隐身窗口的请求,因为它有一个新的会话。

Does anyone know of any way to free up the session to new requests, besides waiting for a timeout? 除了等待超时之外,有没有人知道将会话释放到新请求的任何方法? Is there some way to detect that the client is no longer listening? 有没有办法检测客户端不再监听? I've found Response.IsClientConnected , which seems promising, but I am not sure how it would be used. 我找到了Response.IsClientConnected ,看起来很有希望,但我不确定它会如何使用。

NOTE: This is a legacy application containing a significant amount of business logic, and current conditions do not allow the time or budget for a re-write at this time. 注意:这是一个包含大量业务逻辑的遗留应用程序,当前条件不允许此时重写的时间或预算。 Therefore, suggestions to "just re-write the pages so they load faster" aren't immediately feasible, though I acknowledge that would truly be the best solution. 因此,建议“只是重新编写页面以便加载更快”并不是立即可行的,尽管我承认这确实是最好的解决方案。

Had a similar issue myself regarding concurrency and session state. 关于并发性和会话状态,我自己也遇到过类似的问题。

Try setting enableSessionState="ReadOnly" in your web.config. 尝试在web.config中设置enableSessionState =“ReadOnly”。

See my thoughts here: EnableSessionState = ReadOnly - possible side effects? 在这里看到我的想法: EnableSessionState = ReadOnly - 可能的副作用?

Edit: sorry, saw that you might already have tried doing this. 编辑:抱歉,看到您可能已经尝试过这样做了。

Doing enableSessionState="Readonly" in web.config would improve your performance. 在web.config中执行enableSessionState =“Readonly”可以提高性能。

To allow session write, you can override this setting for a page as, <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="demo.aspx.cs" Inherits="com.Demo" EnableSessionState="true" %> 要允许会话写入,您可以覆盖页面的此设置,因为,<%@ Page Language =“C#”AutoEventWireup =“true”CodeBehind =“demo.aspx.cs”Inherits =“com.Demo” EnableSessionState =“true” %>

Requests for such pages would be served sequentially which makes sense as you are doing changes to session which you wouldn't want to be concurrent to avoid dirty reads. 对这些页面的请求将按顺序提供,这是有意义的,因为您正在对会话进行更改,而您不希望并发以避免脏读。

Have you tried this session less mvc controller for mvc 2 rc ? 你有没有试过这个会话mvc控制器mvc 2 rc

"You have a single client making multiple concurrent requests to the server. The default behavior is that these requests will be serialized; with the session less controller they execute in parallel. " “你有一个客户端向服务器发出多个并发请求。默认行为是这些请求将被序列化;使用会话较少的控制器,它们并行执行。”

That link was old, but maybe you can find your solution following the Session less controller in MVC3 . 这个链接很旧,但也许你可以在MVC3中使用Session less controller找到你的解决方案。

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

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