473,406 Members | 2,439 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,406 software developers and data experts.

Identify User After Session Ends

I am building a web app for users to add/edit data. They may add/edit
several records during a session.
When they are done (not necessarily immediately, could be 10 or more minutes
later), I need to send an email with some summary info of what was
added/edited.
I can keep track of the records by using the sessionid or user's login, but
how can I determine when to send the email and who the user was since there
is no session info available in the session_end event?

This will be on a commercial web server so scheduled tasks is not an option.
Is there some method of looping through the active sessions on an
application level so that I could compare the active sessionid's (or session
variables) with those saved to a db during editing?

TIA

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us

Nov 18 '05 #1
17 2085
"Alphonse Giambrone" <NO**********@example.invalid> wrote in
news:Ob**************@TK2MSFTNGP14.phx.gbl:
I can keep track of the records by using the sessionid or user's
login, but how can I determine when to send the email and who the user
was since there is no session info available in the session_end event?


You could fire off a new thread to do the database work, then send the e-
mail once the thread is done?

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 18 '05 #2
Thanks for the reply Lucas.
I don't quite understand. I don't want to send an email every time the user
edits a record. I want to send it when they are done with ALL their editing.
They may edit 1 record or many and I can't depend on a user clicking a
button when they are done with all.
The concept of session_end would be ideal except when (if) it fires, there
is nothing left to identify who the session belonged to.

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@140.99.99.130.. .
"Alphonse Giambrone" <NO**********@example.invalid> wrote in
news:Ob**************@TK2MSFTNGP14.phx.gbl:
I can keep track of the records by using the sessionid or user's
login, but how can I determine when to send the email and who the user
was since there is no session info available in the session_end event?


You could fire off a new thread to do the database work, then send the e-
mail once the thread is done?

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 18 '05 #3
Hi Alphonse,

From your description, you're building an asp.net web application in which
the users can edit some datas which stored in session and when the user's
session is timeout, we need to send a mail to him with his editing datas.
However, you found its unable to retrieve the sessionid in the Session_end
event , so you're wondering some means to get that, yes?

As for problem, I think maybe cookie is a possible approach, since the
cookies are stored on the client mahcine and still accessable in
Session_End, you can try generate a identical key when the user login and
store in cookie to idenitfy him. And in Session_End , use this cookie value
to get the data for the user.

In addition, the Session_End event seems only work for InProcess Model
session, so if you'll care this problem, there is also another approach
that use the Application Cache to store the user's data. Just define a
certain cache object for storing each user's data and we can specify a
Expire Time and add EXpire event handler for cache object in asp.net.

Just some of my suggestions. Hope helps.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4
Hello,

You could use a domain object that will hold the users information
and when a user logs in, save this object into the session. You will
update the object when the user performs an action on your site like
insert, update, delete record. In the Session_End event you can
retrieve your domain object from the session.

Here is an example which worked for me:

// The domain object
public class User
{
// Unique identifier of the user
private string _id;
// Holds information about the operations that the user performed
in this session
private ArrayList _performedOperations;
public User(string id)
{
_id = id;
_performedOperations = new ArrayList();
}

public string Id
{
get { return _id; }
}

public ArrayList PerformedOperations
{
get { return _performedOperations; }
}

}

protected void Session_Start(Object sender, EventArgs e)
{
User user = new User(Guid.NewGuid().ToString());
Session.Add("user", user);
}
protected void Session_End(Object sender, EventArgs e)
{
User user = (User) Session["user"];
// send email here.
}

Don't forget to adjust the timeout attribute in your web.config
file. For testing you can set its value to 1 and observe that the
Sesssion_End event is fired after 1 min of inactivity from the user.
HTH,

Darin
Nov 18 '05 #5
Steven,

Thanks for the idea. I was not aware of the Expire event handler for cache
objects, but it sounds like it would work.
Do you have an example of using it?
Where is it accessed from, the global.asax?

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:cg**************@cpmsftngxa10.phx.gbl...
Hi Alphonse,

From your description, you're building an asp.net web application in which
the users can edit some datas which stored in session and when the user's
session is timeout, we need to send a mail to him with his editing datas.
However, you found its unable to retrieve the sessionid in the Session_end
event , so you're wondering some means to get that, yes?

As for problem, I think maybe cookie is a possible approach, since the
cookies are stored on the client mahcine and still accessable in
Session_End, you can try generate a identical key when the user login and
store in cookie to idenitfy him. And in Session_End , use this cookie value to get the data for the user.

In addition, the Session_End event seems only work for InProcess Model
session, so if you'll care this problem, there is also another approach
that use the Application Cache to store the user's data. Just define a
certain cache object for storing each user's data and we can specify a
Expire Time and add EXpire event handler for cache object in asp.net.

Just some of my suggestions. Hope helps.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #6
Darin,

Thanks for the interesting suggestion.
Could you please explain a bit.
It seems like you are storing the user object in session.
I had believed that nothing stored in session was available within the
session_end event.

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us
"darin dimitrov" <da************@hotmail.com> wrote in message
news:2b**************************@posting.google.c om...
Hello,

You could use a domain object that will hold the users information
and when a user logs in, save this object into the session. You will
update the object when the user performs an action on your site like
insert, update, delete record. In the Session_End event you can
retrieve your domain object from the session.

Here is an example which worked for me:

// The domain object
public class User
{
// Unique identifier of the user
private string _id;
// Holds information about the operations that the user performed
in this session
private ArrayList _performedOperations;
public User(string id)
{
_id = id;
_performedOperations = new ArrayList();
}

public string Id
{
get { return _id; }
}

public ArrayList PerformedOperations
{
get { return _performedOperations; }
}

}

protected void Session_Start(Object sender, EventArgs e)
{
User user = new User(Guid.NewGuid().ToString());
Session.Add("user", user);
}
protected void Session_End(Object sender, EventArgs e)
{
User user = (User) Session["user"];
// send email here.
}

Don't forget to adjust the timeout attribute in your web.config
file. For testing you can set its value to 1 and observe that the
Sesssion_End event is fired after 1 min of inactivity from the user.
HTH,

Darin

Nov 18 '05 #7
Don't believe you can access session variables from within Session_End.

Greg

"darin dimitrov" <da************@hotmail.com> wrote in message
news:2b**************************@posting.google.c om...
Hello,

You could use a domain object that will hold the users information
and when a user logs in, save this object into the session. You will
update the object when the user performs an action on your site like
insert, update, delete record. In the Session_End event you can
retrieve your domain object from the session.

Here is an example which worked for me:

// The domain object
public class User
{
// Unique identifier of the user
private string _id;
// Holds information about the operations that the user performed
in this session
private ArrayList _performedOperations;
public User(string id)
{
_id = id;
_performedOperations = new ArrayList();
}

public string Id
{
get { return _id; }
}

public ArrayList PerformedOperations
{
get { return _performedOperations; }
}

}

protected void Session_Start(Object sender, EventArgs e)
{
User user = new User(Guid.NewGuid().ToString());
Session.Add("user", user);
}
protected void Session_End(Object sender, EventArgs e)
{
User user = (User) Session["user"];
// send email here.
}

Don't forget to adjust the timeout attribute in your web.config
file. For testing you can set its value to 1 and observe that the
Sesssion_End event is fired after 1 min of inactivity from the user.
HTH,

Darin

Nov 18 '05 #8
Dear newsgroup readers,

Please forgive me if I provided some wrong information as I am not
an advanced .NET developper. What I am sure of although is that the
code snippet I provided works great for me and I can access session
state variables in the Session_End event. The only problem with this
event is that it is fired only if you are using *InProc* as a session
state (never fired if you use StateServer or SQLServer but there is a
workaround).

Thanks,

Darin

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message news:<uo*************@TK2MSFTNGP09.phx.gbl>...
Don't believe you can access session variables from within Session_End.

Nov 18 '05 #9
Hi Alphonse,

As for the cache object's expire event, it is fired when the cache object
will be removed from the application cache and we can register a
OnRemoveCallBack handler for each cache object. Here is the msdn doc
discussing on this:

#Notifying an Application When an Item Is Deleted from the Cache
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconnotifyingapplicationswhenitemisdeletedfromcac he.asp

In addition , below is another tech article which make use of the
OnRemoveCallBack to notify when cache object will expire:
#Prevent Multiple Logins Using the Cache in ASP.NET
http://www.eggheadcafe.com/articles/20030416.asp

Hope also helps. Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Nov 18 '05 #10
Thanks Steven, the articles are very helpful.
I should be able to complete the task with that info although I won't be
able to get back on it until next week.

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:vO**************@cpmsftngxa10.phx.gbl...
Hi Alphonse,

As for the cache object's expire event, it is fired when the cache object
will be removed from the application cache and we can register a
OnRemoveCallBack handler for each cache object. Here is the msdn doc
discussing on this:

#Notifying an Application When an Item Is Deleted from the Cache
http://msdn.microsoft.com/library/de...us/cpguide/htm l/cpconnotifyingapplicationswhenitemisdeletedfromcac he.asp

In addition , below is another tech article which make use of the
OnRemoveCallBack to notify when cache object will expire:
#Prevent Multiple Logins Using the Cache in ASP.NET
http://www.eggheadcafe.com/articles/20030416.asp

Hope also helps. Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #11
Darin,

I did a simple test based on your code and it does indeed work, though as I
previously mentioned I am puzzled as to why.
The difference I see between your code and what I had previously tried is
the method of accessing the session variables.

I had previously tried
HttpContext.Current.Session("mykey") = myval

myval = HttpContext.Current.Session("mykey")
which fails in session_end.

but your method of
Session.Add("mykey", myval)

myval = Session.Item("mykey") or myval = Session("UserID")

does work ( at least in some simple testing) in session_end.

Can anyone explain??
--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us
"darin dimitrov" <da************@hotmail.com> wrote in message
news:2b**************************@posting.google.c om...
Dear newsgroup readers,

Please forgive me if I provided some wrong information as I am not
an advanced .NET developper. What I am sure of although is that the
code snippet I provided works great for me and I can access session
state variables in the Session_End event. The only problem with this
event is that it is fired only if you are using *InProc* as a session
state (never fired if you use StateServer or SQLServer but there is a
workaround).

Thanks,

Darin

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message

news:<uo*************@TK2MSFTNGP09.phx.gbl>...
Don't believe you can access session variables from within Session_End.

Nov 18 '05 #12
I did the same simple test and you guys are right.

In session_end event HttpContext.Current.Session is not accessible, but the
intrinsic Session is.

My apologies for spreading misinformation.

Greg

HttpContext.Current is not valid in Session_End event, but
"Alphonse Giambrone" <NO**********@example.invalid> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Darin,

I did a simple test based on your code and it does indeed work, though as
I
previously mentioned I am puzzled as to why.
The difference I see between your code and what I had previously tried is
the method of accessing the session variables.

I had previously tried
HttpContext.Current.Session("mykey") = myval

myval = HttpContext.Current.Session("mykey")
which fails in session_end.

but your method of
Session.Add("mykey", myval)

myval = Session.Item("mykey") or myval = Session("UserID")

does work ( at least in some simple testing) in session_end.

Can anyone explain??
--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us
"darin dimitrov" <da************@hotmail.com> wrote in message
news:2b**************************@posting.google.c om...
Dear newsgroup readers,

Please forgive me if I provided some wrong information as I am not
an advanced .NET developper. What I am sure of although is that the
code snippet I provided works great for me and I can access session
state variables in the Session_End event. The only problem with this
event is that it is fired only if you are using *InProc* as a session
state (never fired if you use StateServer or SQLServer but there is a
workaround).

Thanks,

Darin

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message

news:<uo*************@TK2MSFTNGP09.phx.gbl>...
> Don't believe you can access session variables from within Session_End.


Nov 18 '05 #13
"Alphonse Giambrone" <NO**********@example.invalid> wrote in message news:<#j**************@TK2MSFTNGP10.phx.gbl>...
Darin,

I did a simple test based on your code and it does indeed work, though as I
previously mentioned I am puzzled as to why.
The difference I see between your code and what I had previously tried is
the method of accessing the session variables.

I had previously tried
HttpContext.Current.Session("mykey") = myval

myval = HttpContext.Current.Session("mykey")
which fails in session_end.

but your method of
Session.Add("mykey", myval)

myval = Session.Item("mykey") or myval = Session("UserID")

does work ( at least in some simple testing) in session_end.

Can anyone explain??

Alphonse,

Here is what is wrong with your code:

The exception you get is because the HttpContext object is null,
not because the Session is null.

When you write: myval = HttpContext.Current.Session("mykey"); in
fact you are using the HttpContext object which is created only when a
new request-response cycle occurs. In the Session_End event there is
no such cycle. Remember the Session_End event is fired only if the
session times out or if you explicitly call Session.Abandon(); so
there is no HttpContext associated. You should instead use the Session
intrinsic as suggested in my snippet in order to retrieve any
information relative to the session.

Another thing to note when dealing with sessions is that the
Session object gets persisted only if it points to some value,
otherwhise it will be null (the session doesn't contain the actual
data you save, it only holds a pointer to this data).

Thanks,

Darin
Nov 18 '05 #14
Darin,

Thanks for the explanation.
That raises another question.
When/how is the 'session' data removed from memory?
The garbage collector?
Or should I be removing it in session_end?

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us
"darin dimitrov" <da************@hotmail.com> wrote in message
news:2b**************************@posting.google.c om...
"Alphonse Giambrone" <NO**********@example.invalid> wrote in message

news:<#j**************@TK2MSFTNGP10.phx.gbl>...
Darin,

I did a simple test based on your code and it does indeed work, though as I previously mentioned I am puzzled as to why.
The difference I see between your code and what I had previously tried is the method of accessing the session variables.

I had previously tried
HttpContext.Current.Session("mykey") = myval

myval = HttpContext.Current.Session("mykey")
which fails in session_end.

but your method of
Session.Add("mykey", myval)

myval = Session.Item("mykey") or myval = Session("UserID")

does work ( at least in some simple testing) in session_end.

Can anyone explain??

Alphonse,

Here is what is wrong with your code:

The exception you get is because the HttpContext object is null,
not because the Session is null.

When you write: myval = HttpContext.Current.Session("mykey"); in
fact you are using the HttpContext object which is created only when a
new request-response cycle occurs. In the Session_End event there is
no such cycle. Remember the Session_End event is fired only if the
session times out or if you explicitly call Session.Abandon(); so
there is no HttpContext associated. You should instead use the Session
intrinsic as suggested in my snippet in order to retrieve any
information relative to the session.

Another thing to note when dealing with sessions is that the
Session object gets persisted only if it points to some value,
otherwhise it will be null (the session doesn't contain the actual
data you save, it only holds a pointer to this data).

Thanks,

Darin

Nov 18 '05 #15
Hi Alphonse,

Don't worry about the Session Datas, though they're still available in the
Session_End event, but that's actually the last time we can access them.
After the Session_End, that Session will be removed and all the datas will
lose reference and waiting for GC to collect them.

If you have anything else unclear, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #16
Thanks Steven, I thought that might be the case but needed to be sure.

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:rQ*************@cpmsftngxa06.phx.gbl...
Hi Alphonse,

Don't worry about the Session Datas, though they're still available in the
Session_End event, but that's actually the last time we can access them.
After the Session_End, that Session will be removed and all the datas will
lose reference and waiting for GC to collect them.

If you have anything else unclear, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #17
You're welcome Alphonse,

If you have any other questions later, please also feel free to post here.
Have a good day!

Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #18

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

Similar topics

5
by: vincent | last post by:
Hi, If i login to the site again (may be in the same pc or different pc), system must allow me in and end my previous session. How do i go about doing this? This is to ensure that an user...
1
by: Lawrance | last post by:
DearAll: How do I restrict to the same user's double_login? Is there any way to solve this problem under "user closed browser" or "computer crash" condition ? Best Regards, Lawrance Chang
3
by: Dan Walls | last post by:
Hi, I am looking to clean up some database locks whenever a user session ends. A user session ends whenever they: a. shut down the browser and the session times out after 20 mins (20 mins is...
8
by: Razak | last post by:
Hi, I have a class which basically do Impersonation in my web application. From MS KB sample:- ++++++++++++++++++++code starts Dim impersonationContext As...
5
by: news.microsoft.com | last post by:
Hi everyone, I need some help (may be in the form of some sample code) for the subject question. I have an ASP.NET/C# application. I need to do quite a few tasks when the session ends. I...
3
by: Michel | last post by:
Hi, I wrote an app in .Net and I whant only 1 instance of this app open for the user; the user open my app, do some works and try to open another instance of my app, I whant to show a message to...
13
by: Laurahn | last post by:
How can i configure my application for closing the session ? How can i use the session end for closing the session ?
9
by: dudelideisann | last post by:
Hi! I have a form where the user enters some input. The input will eventionally become a database table. When he hit the 'submit' button the info is put into an array and then into a session...
5
by: Ron J | last post by:
I would like to keep track of users when they are 'on'. On Session_Start I can write a DB record about them, but there does not seem to be session variable information during the Session_end event...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.