ASP.NET - 从客户端访问Web页面的两倍 [英] ASP.NET - Accessing web page twice from client
问题描述
如果一个用户尝试的第一页被返回到客户端之前两次访问ASP.NET页面会发生什么?看看下面的code:
What happens if one user tries to access an ASP.NET page twice before the first page is returned to the client? Have a look at the code below:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Session("ID") = 1
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Redirect("Default3.aspx")
End Sub End Class
Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Session("ID") = 2
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Redirect("Default3.aspx")
End Sub
End Class
Imports System.Threading
Partial Class Default3
Inherits System.Web.UI.Page
Dim intTest As Integer = 0
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
For intTest = 0 To 10
Response.Write(Session("ID") & " " & intTest & "<br>")
Thread.Sleep(1000)
Next
End Sub
End Class
来自同一客户端(PC)访问default3.axpx同时从Default.aspx的(通过点击按钮),default2.aspx(点击按钮)导致会话变量是在这两个请求相同的(虽然我设置变量1上的第二第一请求和2)。是否有可能复制这种行为,而不线程?我相信我有在不使用线程的asp.net应用程序这个bug。
Accessing default3.axpx from the same client (PC) concurrently from default.aspx (by clicking button) and default2.aspx (by clicking button) causes the session variable to be the same on both requests (though I set the variable to 1 on the first request and 2 on the second). Is it possible to replicate this behaviour without threading? I believe I have this bug in an asp.net application that does not use threading.
推荐答案
您的问题是不是多线程;它是关于SessionState会。
Your question is not about multi-threading; it is about SessionState.
ASP.NET运行时使用 锁,以避免覆盖相同的会话变量 的虽然它可以处理多个请求。
ASP.NET run time uses lock to avoid overriding same session variables although it can handles multiple requests.
这就是为什么你看不到错过匹配的结果。
It's why you are do not see miss-matching results.
也请看 -
这篇关于ASP.NET - 从客户端访问Web页面的两倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!