473,657 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("U serName")
set RS = server.createob ject("ADODB.rec ordset")
MySql="select * from empprofile where empname ='" & strUserName & "'"
RS.Open MYSql, CONN_STRING

if not RS.eof then
session("UserNa me") = strUserName
session("Email" ) = RS("Email")
response.redire ct("displayholi days.asp")
end if

on the display holidays page I run a query like

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

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 1527
> 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_n ame")="" Then
blah
End if
%>

Where blah for example could be a response.redire ct 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" <djmarsatAThotm ail.com> wrote in message
news:u$******** ******@TK2MSFTN GP11.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_n ame")="" Then
blah
End if
%>

Where blah for example could be a response.redire ct 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" <djmarsatAThotm ail.com> wrote in message
news:eh******** ******@TK2MSFTN GP10.phx.gbl...
Or, you could use a form and post the user
data to each page to avoid using session
variables

"Dominic Marsat" <djmarsatAThotm ail.com> wrote in message
news:u$******** ******@TK2MSFTN GP11.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_n ame")="" Then
blah
End if
%>

Where blah for example could be a response.redire ct 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
4016
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 OTHER session variables are still intact !?! TIA, Larry Woods
0
1882
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: Mittwoch, 16. Juli 2003 11:19 An: mysql@lists.mysql.com Betreff: Re: switch query logging while the server is running
1
1422
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. Nevertheless, if in the same session I set the variables again, they don't get lost anymore. What could be the reason for the session variables to get lost in the beginning of the session? Could it be a size issue? Where can I set amount of storage...
4
5581
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 immediate window will show the values in Session after the relevant lines that set the variables in the Page_Unload event. However, on postback, these variables are no longer in Session. All Session variables that were set previous to that particular...
1
1780
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 project from that other server, the session state variables are being set randomly. For example, in the following code: SetSelectionSessionState();...
2
1422
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 logoff button which does another Response.Redirect(main url); Here is the issue, I am able to browse back to that page and the data is still populated and visible. How can I clear the cache for that page? I have tried: Response.Expires = 0;...
10
2182
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 how to open the windows with different sessionID. Thanks
18
3432
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 File-New-Window creates an instance of IE in the same process with the same SessionID as the parent window is in big trouble. This fundamentally restricts the usefullness of using session state management. I probably missed it somewhere - can...
14
2287
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. In IIS the virtual directory configuration setting is set to 40. The application still timesout at 20 minutes. What else can I do? --
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.