Depending on the function the user is trying to access, I may only need to pull one value. I'm not real saavy on how cookies work code wise so I gravitated to the path of least resistance.
Why don't you just create a User Class:
-
Public Class MySiteUser
-
Private _userID
-
Private _pwd
-
Public Property UserID As String
-
Get
-
Return _userID
-
End Get
-
Set(ByVal value As String)
-
_userID=value
-
End Set
-
End Property
-
Public Property PWD As String
-
Get
-
Return _pwd
-
End Get
-
Set(ByVal value As String)
-
_pwd=value
-
End Set
-
End Property
-
Public Function ValidateUser As Boolean
-
'If the user is valid pass back true otherwise false
-
End Function
-
Public Sub New(ByVal name As String, ByVal pwd As String)
-
'lalala initialize
-
End Sub
-
End Class
-
When the user visits your site, create an instance of your user class and store it in session. A Session Identifier Cookie is automatically set for the user to identify their browser with their session. Then you can check the user on any page in your website by checking the user class...
-
Private _theUser As MySiteUser
-
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
_theUser = Session("_theUser")
-
If _theUser is Nothing OrElse _theUser.ValidateUser = False
-
Response.Redirect("Invalid.aspx")
-
End IF
-
End Sub
-
Of course you're going to have to create this variable and store it in session in your Login Page:
-
Private _theUser As MySiteUser
-
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
_theUser = Session("_theUser")
-
If _theUser is Nothing OrElse _theUser.ValidateUser = False
-
_theUser = New MySiteUser(TXT_LoginName.Text, TXT_PWD.Text)
-
Session("_theUser") = _theUser
-
End IF
-
If _theUser.ValidateUser = True Then
-
Response.Redirect("WelcomeDefault.aspx")
-
Else
-
LBL_Error.Text="You have provided invalid crednetials"
-
End If
-
End Sub
-
Of course the examples I've provided by no means provide any security on passwords. You shouldn't be storing passwords anyways...especially not in cookies. You should research how password hashes work and how you can use them...
Also, by using sessions instead of cookies stores important user information on your server instead of the client's browser...where they are vulnerable to being stolen, modified... etc.
The User Class can be used to track anything you want....where they've been in the site...what they have already provided on another page....anything you want really.
Check out this quick overview of
Sessions...I think it'll help you get a better understanding of how to use them.
-Frinny