Session Problems

Tech-Archive recommends: Speed Up your PC by fixing your registry



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?
.



Relevant Pages

  • Matching 3 criteria for a valid login?(Loging code included)
    ... Valid(username, pass and status) is the only way one can access the ... Private Sub Command1_Click ... Dim username As String ...
    (microsoft.public.vb.general.discussion)
  • Re: I cant log into my own account.
    ... which I thought was a bit weird since my username IS the ... admin, and access the files that way. ... Do you ACTUALLY logon as "administrator"? ... Since you mentioned 'Safe Mode, logon as administrator' --> Can I assume you ...
    (microsoft.public.windowsxp.general)
  • Re: Generate usernames from Hostnames.
    ... It should only remove the first zero from the numeric part. ... username = user123 ... 200 Machines one common admin password but admin username is derived ... from the hostname. ...
    (microsoft.public.windows.server.scripting)
  • wsf-Script "Das Objekt unterstützt diese Eigenschaft oder Methode nicht"
    ... Die ist zuständig für eine Remotedesktop-Webverbindung ... Mit folgender wsf-Datei wurde eine Web-Remotedesktopverbindung gestartet: ... username = "username" ' name of the user logging on ... Sub RdpCall ...
    (microsoft.public.de.vb)
  • Re: Personal Data and Security
    ... No. He's saying that the admin page username and password are not the same ... or someone who gets access to your network can lock you out. ... Also, if the router happens ...
    (comp.sys.mac.apps)