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

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

问题描述

ASP.NET不允许在同一会话并发请求;这意味着用户只能做一次1请求。

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

For example, say we have 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");
    }
  }

当我们访问 Test1.aspx?超时= 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).

那么,有没有办法迫使并发?也就是说,不是使网页的速度更快,或移动长期运行code到后台线程等。我知道,你可以只读会话,但我不能完全肯定这是一个可行的选择。

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.

像你所说,保持请求短,移动长期运行code OUT请求的线程。另外:

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天全站免登陆