Session Problems

R

RN1

I have a login ASPX page with 2 textboxes - one for username & the
other for password - & a checkbox whose ID is chkAdmin. The checkbox
is for logging as admin. The SQL Server 2005 DB table that stores all
the user details has a column named IsAdmin whose datatype is bit. If
a record under this column is True, the user is admin else the user is
non-admin. This is the stored procedure to validate users:

CREATE PROCEDURE [dbo].[LoginUser]
@UserName varchar(50),
@Password varchar(50)
AS
DECLARE
@UserID int

IF NOT EXISTS (SELECT UID FROM LoginUsers WHERE UserName = @UserName
AND Password = @Password)
BEGIN
SET @UserID = 2
END
ELSE
BEGIN
SET @UserID = (SELECT IsAdmin FROM LoginUsers WHERE UserName =
@UserName AND Password = @Password)
END
RETURN @UserID

This is the login code:

Sub LoginUser(ByVal obj As Object, ByVal ea As EventArgs)
Dim iUID As Integer

iUID = Validate(txtUserName.Text, txtPassword.Text)

If (iUID = 2) Then
Response.Write("Invalid User")
Else
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text,
True)
If (chkAdmin.Checked = False) Then
Session("Admin") = 0
ElseIf (chkAdmin.Checked = True And iUID = 0) Then
Session("Admin") = 0
ElseIf (chkAdmin.Checked = True Or iUID = 1) Then
Session("Admin") = 1
End If
End If
Response.Redirect("Page1.aspx")
End Sub

Please note that the Validate function is not shown here.

Page1.aspx displays records from another DB table which has 5 columns.
If a user has logged in as admin, Page1.aspx will display records from
all the 5 columns but if he has logged in as a normal user, Page1.aspx
will display records from only 3 columns. This is the code in
Page1.aspx:

Sub Page_Load(.....)
Response.Write(Session("Admin"))
If (Session("Admin") = 0) Then
'select records from all 5 columns
ElseIf (Session("Admin") = 1) Then
'select records from only 3 columns
End If
End Sub

Assume that a user logs in as admin i.e. Session("Admin") is 1.
Page1.aspx displays records from all the 5 columns. The problem is
under such circumstances after around 10 minutes when I refresh
Page1.aspx, due to some reason, Session("Admin") automatically resets
itself to 0. As a result, Page1.aspx displays records from only 3
columns & not all the 5 columns.

What could be causing this problem & how do I overcome it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top