Reputation: 119
How to store user id in session so that I can use in other pages?
My code is as follows
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()
but its showing error as:
session is not declared
Upvotes: 2
Views: 44599
Reputation: 3750
You get this error when compiling your application:
Name 'session' is not declared ...
This generally occurs when using session variables in a code customization and your compiler is not able to find the session variable class.
Specify the full path of the session variable. If you cannot access the Session class directly, you may need to specify its full path as follows:
In VB.NET, to access a value:
System.Web.HttpContext.Current.Session(“MyVariable”)
System.Web.HttpContext.Current.Session(“MyVariable”).ToString()
In VB.NET, to set a value:
System.Web.HttpContext.Current.Session(“MyVariable”) = “NewValue”
Upvotes: 8