473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Logging in Session Variables Issue

Hi All

We have an ASP application which tracks holidays for our employees. When the
user logs in we store thier username in a session variable and use that
variable when displaying and adding data to the access database. The
username is the primary key for the database table.

strUsername = request.form("UserName")
set RS = server.createobject("ADODB.recordset")
MySql="select * from empprofile where empname ='" & strUserName & "'"
RS.Open MYSql, CONN_STRING

if not RS.eof then
session("UserName") = strUserName
session("Email") = RS("Email")
response.redirect("displayholidays.asp")
end if

on the display holidays page I run a query like

Select * from HolidayRequest where Username = '" & session("Username") & "'"

to display the holiday records for that employee.

I have two questions.

1. Is it a good practice to store the username in a session variable to keep
track of who is logged in?

2. Sometimes when a user is logged in for too long without any activity the
session variable clears and when adding or displaying records it gives an
error. What I would like to do is somehow keep a track and if at all the
session variable expires for it to display a message that "You have been
logged off" please login again but logging in again should take the user
back to the page which logged them out.

Many thanks for your help in advance.
Jul 19 '05 #1
3 1513
> 1. Is it a good practice to store the username in a session variable to
keep
track of who is logged in?
You don't really have a choice because the HTTP protocol that you
use to browse is stateless, therefore, each request for a page is
completely independant of earlier requests.

Using a session variable is fine. I think it's only really an issue
for very busy web servers.

2. Sometimes when a user is logged in for too long without any activity the session variable clears and when adding or displaying records it gives an
error. What I would like to do is somehow keep a track and if at all the
session variable expires for it to display a message that "You have been
logged off" please login again but logging in again should take the user
back to the page which logged them out.


Just check for when the variable contains nothing

i.e.

<%
If Session("user_name")="" Then
blah
End if
%>

Where blah for example could be a response.redirect to
another page displaying the logged off message.

Note, that you can change the session time out in the IIS
control panel or using VB script.

Jul 19 '05 #2
Or, you could use a form and post the user
data to each page to avoid using session
variables

"Dominic Marsat" <djmarsatAThotmail.com> wrote in message
news:u$**************@TK2MSFTNGP11.phx.gbl...
1. Is it a good practice to store the username in a session variable to

keep
track of who is logged in?


You don't really have a choice because the HTTP protocol that you
use to browse is stateless, therefore, each request for a page is
completely independant of earlier requests.

Using a session variable is fine. I think it's only really an issue
for very busy web servers.

2. Sometimes when a user is logged in for too long without any activity

the
session variable clears and when adding or displaying records it gives an error. What I would like to do is somehow keep a track and if at all the
session variable expires for it to display a message that "You have been
logged off" please login again but logging in again should take the user
back to the page which logged them out.


Just check for when the variable contains nothing

i.e.

<%
If Session("user_name")="" Then
blah
End if
%>

Where blah for example could be a response.redirect to
another page displaying the logged off message.

Note, that you can change the session time out in the IIS
control panel or using VB script.

Jul 19 '05 #3
Thanks Dominic

That was exactly what I was after

thanks
"Dominic Marsat" <djmarsatAThotmail.com> wrote in message
news:eh**************@TK2MSFTNGP10.phx.gbl...
Or, you could use a form and post the user
data to each page to avoid using session
variables

"Dominic Marsat" <djmarsatAThotmail.com> wrote in message
news:u$**************@TK2MSFTNGP11.phx.gbl...
1. Is it a good practice to store the username in a session variable to
keep
track of who is logged in?


You don't really have a choice because the HTTP protocol that you
use to browse is stateless, therefore, each request for a page is
completely independant of earlier requests.

Using a session variable is fine. I think it's only really an issue
for very busy web servers.

2. Sometimes when a user is logged in for too long without any
activity
the
session variable clears and when adding or displaying records it gives

an error. What I would like to do is somehow keep a track and if at all

the session variable expires for it to display a message that "You have been logged off" please login again but logging in again should take the user back to the page which logged them out.


Just check for when the variable contains nothing

i.e.

<%
If Session("user_name")="" Then
blah
End if
%>

Where blah for example could be a response.redirect to
another page displaying the logged off message.

Note, that you can change the session time out in the IIS
control panel or using VB script.


Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Larry Woods | last post by:
I am losing Session variables, but only those that are set in the page previous to a redirect to a secure page. Anyone seen ANY situation where Session variables just "disappear?" Note that...
0
by: Moritz Steiner | last post by:
Ok, but this only works for the current session, if I close and restart = the client the settings are reset... -----Urspr=FCngliche Nachricht----- Von: Victoria Reznichenko =20 Gesendet:...
1
by: Eliyahu Goldin | last post by:
When I run my ASP.NET application first time after deployment, it runs OK. On the second run, when one of my web forms tries to read session variables set in another form, it finds them empty....
4
by: PJ | last post by:
A particular page seems to be having issues with correctly setting Session variables. I am setting a couple of session variables on the Page_Unload event. While stepping through code, the...
1
by: yoshibebe | last post by:
Hi, I have developed a project on my local machine. The session state variables are working fine on my local machine. When I port it into a another server called v-projects, and I try to run the...
2
by: Terry | last post by:
Hello everyone, I created a logon page using C# ASPX, I have the user logon and if logon information is correct I do a Response.Redirect(url); On the second page it displays data and I have a...
10
by: Li Pang | last post by:
Hi, I created a html page from which I give a link to another web site. The new site is opened in a new window. When I opened multiple windows, they all have the same SessionID. I want ot know...
18
by: BillE | last post by:
When a user opens a new IE browser window using File-New-Window the integrity of an application which relies on session state is COMPLETELY undermined. Anyone who overlooks the fact that...
14
by: GaryDean | last post by:
The web.config in my asp.net application, running on Server2003, has this entry: <sessionState mode="InProc" timeout="40". In IIS the asp.net State Management timeout setting is 40 for my website....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.