如果一个用户在第一个页面返回给客户端之前尝试访问 ASP.NET 页面两次会发生什么?看看下面的代码:
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
从 default.aspx(通过单击按钮)和 default2.aspx(通过单击按钮)同时从同一客户端 (PC) 访问 default3.axpx 会导致会话变量在两个请求上相同(尽管我将变量设置为 1 on第一个请求和第二个请求 2)。是否可以在没有线程的情况下复制这种行为?我相信我在不使用线程的 asp.net 应用程序中有这个错误。