是否可以在使用ASP.NET会话时强制请求并发? [英] Is it possible to force request concurrency when using ASP.NET sessions?

查看:113
本文介绍了是否可以在使用ASP.NET会话时强制请求并发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP.NET不允许同一会话的并发请求;

ASP.NET does not allow concurrent requests for the same session; meaning that a user can only make 1 request at a time.

例如,假设我们有 Test1.aspx

  public partial class Test1 : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      Session["test"] = 1;
      System.Threading.Thread.Sleep(int.Parse(Request.QueryString["timeout"]));
    }
  }

...和 Test2 .aspx

  public partial class Test2 : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      Session["test"] = 1;
      Label1.Text = DateTime.Now.ToString("dd/MM/yy HH:mm:ss");
    }
  }



< aspx?timeout = 10000 ,然后在访问 Page2.aspx 后立即,第二个请求将必须等待10秒,直到第一个请求完成。

When we visit Test1.aspx?timeout=10000, and then immediately after visit Page2.aspx, the 2nd request will have to wait for 10 seconds until the first request has finished.

我刚刚学习了这个,我已经使用ASP.NET 5年了!我真的不相信,直到我读它在MSDN页面的底部( ASP.NET会话状态概述)。

I just learnt this today, and I've been using ASP.NET for 5 years! I didn't really believe it until I read it at the bottom of an MSDN page (ASP.NET Session State Overview).

那么,有没有办法强制并发?也就是说,除了使页面更快,或者将长时间运行的代码移动到后台线程。我知道你可以使会话只读,但我不完全确定这是一个实用的选择。

So, is there a way to force concurrency? That is, other than making pages faster, or moving long running code to a background thread. I'm aware that you can make the session read only, but I'm not entirely sure this is a practical option.

推荐答案

虽然我刚刚从这个问题学到这一点,我会确保检查实现会话状态存储提供程序,以获取有关其完成原因的更多信息。

Although I just learned this from the question, I'd make sure to check the Locking Session-Store Data section in Implementing a Session-State Store Provider, for more information on the why its done.

基于上述,似乎不是一个好主意,试图解决这个机制。

Based on the above, it really doesn't seem like a good idea to try to work around that mechanism.

像你提到的,保持请求短,将长时间运行的代码移出请求线程。此外:

Like you mentioned, keep the requests short and move long running code out of the request thread. Additionally:


  • 如果您不需要,禁用会话。

  • 避免不必要的会话使用。

所有这些都是你应该已经做的事情。

All of those are something you should already be doing anyway.

这篇关于是否可以在使用ASP.NET会话时强制请求并发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆