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 17 2050
"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/
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/
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.)
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
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.)
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
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
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.
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.)
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.)
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.
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.
"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
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
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.)
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.)
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.) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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 ?
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |