如何在会话中存储用户 ID,以便我可以在其他页面中使用?
我的代码如下
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Web
Imports System.IO
Private Sub cmdlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
cnn.Open()
Dim sqlcomm2 As New SqlCommand("Select * from Users where userid='" & txtuserid.Text & "'", cnn)
Dim r2 As SqlDataReader = sqlcomm2.ExecuteReader()
While r2.Read
Dim UserId1 As String = Trim(UCase(CStr(r2("UserId"))))
Dim Password As String = Trim(UCase(CStr(r2("Password"))))
Dim username As String = CStr(r2("Name"))
Session("User") = UserId1
Session("Password") = Password
'System.Web.HttpContext.Current.Session("item")
End While
r2.Close()
但其显示错误为:
会话未声明