gpt4 book ai didi

c# - PageMethods 和 session

转载 作者:行者123 更新时间:2023-11-30 17:19:15 33 4
gpt4 key购买 nike

我到处搜索这个解决方案。任何见解将不胜感激。

情况:当在单个页面中有多个 PageMethod 调用时,每个方法调用都持有 Session 对象的锁,从而阻塞。只有当 @Page 指令变为 False|ReadOnly

时,PageMethod 调用才能异步进行

调查结果:当 Page 指令为默认(读/写)但页面上的任何地方都没有使用 session 时,调用不会被阻止。在页面级别对 session 的任何读取或写入都会阻止页面方法调用。

问题:在 @Page 指令中设置 EnableSessionState=ReadOnly 是非常严格的,不想采用这种方式。

pagemethod调用可以不阻塞吗?并仍然访问 session ? (可能不是写而是读)

最佳答案

如果不实现自己的 session 提供程序,我认为您无法做到这一点。有 some info on this MSDN page .

ASP.NET applications are inherently multithreaded. Because requests that arrive in parallel are processed on concurrent threads drawn from a thread pool, it's possible that two or more requests targeting the same session will execute at the same time. (The classic example is when a page contains two frames, each targeting a different ASPX in the same application, causing the browser to submit overlapping requests for the two pages.) To avoid data collisions and erratic behavior, the provider "locks" the session when it begins processing the first request, causing other requests targeting the same session to wait for the lock to come free.

Because there's no harm in allowing concurrent requests to perform overlapping reads, the lock is typically implemented as a reader/writer lock-that is, one that allows any number of threads to read a session but that prevents overlapping reads and writes as well as overlapping writes.

关于c# - PageMethods 和 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5110001/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com