473,804 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Alternative to Session_End

Hi

I am using StateServer as my sessionState mode. I realise that I cannot
use the Session_End in global.asax. I just want to do some simple
logging of site usage.

Has anybody got a simple solution that replaces the Session_End object?

I was thinking of using client-side script to redirect to another page.
I can then use this page to enter the information I require into the
database. Is there any script that will see the Page Unload event? I
realise that this may not function in all browsers, but the site is
currently only intranet based, so it's not an issue right now.

Thanks

Jared

Jan 17 '06 #1
7 4473
You could just have a logout page and perfom your processing here. Keep in
mind though that the user might well just close directly the browser (you
could likely still use client side script events and call a server side
page).

What is the exact information you want ?

You could work with HTTP rather than against and base the end of the session
(if this is what you are after) on the last HTTP request the server gets
rather than on the actual time where the user closed his browser (he could
go to lunch and close it or forget it under other windows and close it, how
valuable it is to get the time he closed the window compared with the time
he lasked ask something to the server ?) You can eventually add the default
timeout so that you are lined up with the technical end of the session...

--
Patrice

"Jared" <ja***********@ gmail.com> a écrit dans le message de
news:11******** *************@g 47g2000cwa.goog legroups.com...
Hi

I am using StateServer as my sessionState mode. I realise that I cannot
use the Session_End in global.asax. I just want to do some simple
logging of site usage.

Has anybody got a simple solution that replaces the Session_End object?

I was thinking of using client-side script to redirect to another page.
I can then use this page to enter the information I require into the
database. Is there any script that will see the Page Unload event? I
realise that this may not function in all browsers, but the site is
currently only intranet based, so it's not an issue right now.

Thanks

Jared

Jan 17 '06 #2
Patrice

Thanks for your quick response.

I want the user to be able to close the browser to log-off. I already
have a logoff button, but do not want to force them to use that, unless
I can with client-side script.

How would I record the user asking something? Would I use
Application_End Request?

Many Thanks

Jared

Jan 17 '06 #3
For any body that's interested I have found a solution to this problem
that works for me.

What I do is use javascript to detect whether the close button has been
clicked on the browser and launch a pop-up window, which populates my
database and ends my session if it has. The basic code is here;
//This Code goes in the page_load event for each page in the
application. This code is just registering the javascript.

if(!this.IsClie ntScriptBlockRe gistered("clien tScript"))
this.Page.Regis terClientScript Block("clientSc ript",strScript );
//This code goes in the Body html tag of each page in the application

<Body onunload="logof f('logout.aspx' )">
//This is the javascript to check for the browser close button and open
a log-off
//pop-up window (strScript in the example above).

//You can type this javascript directly into the html of each page and
it has
//the same effect, but there is less manipulation involved if you store
it in a class.

//The important bit is "if (event.clientY < 0)", becuase this
determines whether or not
//the close (x) button has been clicked, by looking at the mouse
pointer location.
<script language=javasc ript>
<!--
var newwindow = ''
function logoff(url)
{
if (event.clientY < 0)
{
if (!newwindow.clo sed && newwindow.locat ion)
{
newwindow.locat ion.href = url;
}
else
{
newwindow=windo w.open(url,'Log out','height=15 0,width=100');
if (!newwindow.ope ner) newwindow.opene r = self;
}
}
if (window.focus)
{
newwindow.focus ()
}
return false;
}
// -->
</script>
//This is the code on the Page_Load event of logoff.aspx. In this
example I
//use Session["strUserID"] to determine whether or
//not the user has logged in to the web-site, as this is optional. The
pop-up window
//closes automatically if the user has not logged in.
//I have a call to a function which populates my database log info here
first, then;

if((string)Sess ion["strUserID"] == "")
{
Page.RegisterSt artupScript("Cl oseScript","<sc ript language=javasc ript>
window.close(); </script>");
}
else
{
lblMessage.Text = "<p align=center>Br ands Manual<br><br>L ogout
Successful<br>< br><a
href='javascrip t:window.close( )'>Close</a></font>";
}
Session.Abandon ();

Jan 17 '06 #4
Try adding expanding the javascript function to include
'event.clientX' . I noticed in the example below that when the
navigation buttons were clicked the pop-up was displayed. Adding this
extra bit seems to cure the issue.

if (event.clientY < 0 && event.clientX <0)
Jared wrote:
For any body that's interested I have found a solution to this problem
that works for me.

What I do is use javascript to detect whether the close button has been
clicked on the browser and launch a pop-up window, which populates my
database and ends my session if it has. The basic code is here;
//This Code goes in the page_load event for each page in the
application. This code is just registering the javascript.

if(!this.IsClie ntScriptBlockRe gistered("clien tScript"))
this.Page.Regis terClientScript Block("clientSc ript",strScript );
//This code goes in the Body html tag of each page in the application

<Body onunload="logof f('logout.aspx' )">
//This is the javascript to check for the browser close button and open
a log-off
//pop-up window (strScript in the example above).

//You can type this javascript directly into the html of each page and
it has
//the same effect, but there is less manipulation involved if you store
it in a class.

//The important bit is "if (event.clientY < 0)", becuase this
determines whether or not
//the close (x) button has been clicked, by looking at the mouse
pointer location.
<script language=javasc ript>
<!--
var newwindow = ''
function logoff(url)
{
if (event.clientY < 0)
{
if (!newwindow.clo sed && newwindow.locat ion)
{
newwindow.locat ion.href = url;
}
else
{
newwindow=windo w.open(url,'Log out','height=15 0,width=100');
if (!newwindow.ope ner) newwindow.opene r = self;
}
}
if (window.focus)
{
newwindow.focus ()
}
return false;
}
// -->
</script>
//This is the code on the Page_Load event of logoff.aspx. In this
example I
//use Session["strUserID"] to determine whether or
//not the user has logged in to the web-site, as this is optional. The
pop-up window
//closes automatically if the user has not logged in.
//I have a call to a function which populates my database log info here
first, then;

if((string)Sess ion["strUserID"] == "")
{
Page.RegisterSt artupScript("Cl oseScript","<sc ript language=javasc ript>
window.close(); </script>");
}
else
{
lblMessage.Text = "<p align=center>Br ands Manual<br><br>L ogout
Successful<br>< br><a
href='javascrip t:window.close( )'>Close</a></font>";
}
Session.Abandon ();


Jan 17 '06 #5
KMA
I can see that it's possible to detect when the close button is clicked. But
what if the user uses AltF4 to close the browser? Wouldn't you favour a
server side solution?
"Jared" <ja***********@ gmail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
Try adding expanding the javascript function to include
'event.clientX' . I noticed in the example below that when the
navigation buttons were clicked the pop-up was displayed. Adding this
extra bit seems to cure the issue.

if (event.clientY < 0 && event.clientX <0)
Jared wrote:
For any body that's interested I have found a solution to this problem
that works for me.

What I do is use javascript to detect whether the close button has been
clicked on the browser and launch a pop-up window, which populates my
database and ends my session if it has. The basic code is here;
//This Code goes in the page_load event for each page in the
application. This code is just registering the javascript.

if(!this.IsClie ntScriptBlockRe gistered("clien tScript"))
this.Page.Regis terClientScript Block("clientSc ript",strScript );
//This code goes in the Body html tag of each page in the application

<Body onunload="logof f('logout.aspx' )">
//This is the javascript to check for the browser close button and open
a log-off
//pop-up window (strScript in the example above).

//You can type this javascript directly into the html of each page and
it has
//the same effect, but there is less manipulation involved if you store
it in a class.

//The important bit is "if (event.clientY < 0)", becuase this
determines whether or not
//the close (x) button has been clicked, by looking at the mouse
pointer location.
<script language=javasc ript>
<!--
var newwindow = ''
function logoff(url)
{
if (event.clientY < 0)
{
if (!newwindow.clo sed && newwindow.locat ion)
{
newwindow.locat ion.href = url;
}
else
{
newwindow=windo w.open(url,'Log out','height=15 0,width=100');
if (!newwindow.ope ner) newwindow.opene r = self;
}
}
if (window.focus)
{
newwindow.focus ()
}
return false;
}
// -->
</script>
//This is the code on the Page_Load event of logoff.aspx. In this
example I
//use Session["strUserID"] to determine whether or
//not the user has logged in to the web-site, as this is optional. The
pop-up window
//closes automatically if the user has not logged in.
//I have a call to a function which populates my database log info here
first, then;

if((string)Sess ion["strUserID"] == "")
{
Page.RegisterSt artupScript("Cl oseScript","<sc ript language=javasc ript>
window.close(); </script>");
}
else
{
lblMessage.Text = "<p align=center>Br ands Manual<br><br>L ogout
Successful<br>< br><a
href='javascrip t:window.close( )'>Close</a></font>";
}
Session.Abandon ();

Jan 18 '06 #6
I see where you are coming from (I am just banking on my users not
using Alt-F4) for now). I would prefer a server-side solution, but it
is not made easy when using StateServer. Do you have a server-side
solution that is simple to implement?

Thanks

Jared

Jan 18 '06 #7
Managed to find this javascript that detects Alt-F4 and opens a message
box. Although the cancel routine does not work, the fact that the
message box is modal, means that the pointer co-ordinates from my
previous code work and I get my session ended.

function CheckKeys()
{
function cancel()
{
// local function
event.keyCode = 0;
event.cancelBub ble = true;
return false;
}
var allowedBack = "INPUT,TEXTAREA ,";
with(event)
{
//alert("keyCode: "+keyCode);
if(altLeft&&key Code==115)
{
// ALT+F4
alert("ALT+F4") ; // this work
return cancel(); // this not working
}
}
}

Jared

Jan 18 '06 #8

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

Similar topics

2
11392
by: Chris Sibel | last post by:
Hey guys I have a user tracking setup to track users. What it does is once a user hits my site it sends me an email telling me some info and once a user clicks the logout button it sends a second email that tells me what pages the visited, how long they were on each page, etc. The second email is in the Session_End Sub and the first is in the Session_Start. Now my question is Why is it that the Session_End is never fired. I was forced to...
9
10804
by: Kenn Ghannon | last post by:
I've got an ASP.NET page with a counter subtraction routine in the Session_End method in the Global.asax.cs: protected void Session_End(Object sender, EventArgs e) { ulong curUsers; Application.Lock();
2
4735
by: Bela | last post by:
Hello I was wondering if someone could help me out with a Session_End problem in my Global.asax. I've tried everything, and still no success Here is the scenario: sessionstate is set to InProc. I have timeout set to 1 min I have a variable in session_start that is incremented each new session, and it is then decremented in Session_End. I use this variable on a web form to show current users online. All of this works just fine, so I...
3
566
by: Guadala Harry | last post by:
Just wondering if Session_End *always fires* for every Session. I know that IIS times out sessions after a default 20 min (unless changed) and there's no way to know when a user actually closed a browser (unless I provide a "log out" button that kills the session explicitly, and we can't guarantee the user will click on that). What I am wondering if there are there well-known/documented circumstances under which Session_End will NOT fire...
4
9188
by: Kim Bach Petersen | last post by:
I would like to record user behavior data stored in session variables. Since the data is modified throughout each session it seemed obvious to store the data when the session terminates - using Session_End in global.asax. Problem is, apparently the session-object terminating cannot be accessed from Session_End in global.asax!? What's the meaning of Session_End if you don't know which session is
7
1645
by: Henry | last post by:
I have a question on session_end. I'm trying to log into my database when the session times out, it will store user info into a table. When I got step into a line where I was trying to open connection (I had it set to timeout in 1 minute, and ran it in debug mode), nothing happens. I read somewhere before about how database call can't work with these settings in my web.config file. I'm using <authentication mode="Windows" /> and <identity...
8
5772
by: Roger | last post by:
When I call the session.abandon() method, it calls the session_end event. When a user closes the browser or clicks the log off button, I can dispose of objects and abandon the session cleaning. But, when a user either navigates away from the web app and when the session timesout, the session_end event does not seem to fire. Or when else can I dispose of objects? Or is there an event I can you that is fired when a user navigates away from...
1
6949
by: =?Utf-8?B?YnJlbnQ5NjA=?= | last post by:
Environment: ASP.NET 2.0, SQL Server 2005, C#, Visual Studio 2005 In my Session_End event, I am executing a stored procedure to update a database table that is used to log user sessions. When the user sessions time out, the Session_End event fires successfully. The stored procedure executes successfully, and I can see the updated data in the database just as I would expect. Nonetheless, an exception is being generated by the code...
12
10716
by: =?Utf-8?B?QWxleCBNYWdoZW4=?= | last post by:
Hi. I am trying to maintain a list of people who are currently "online" in SQL. I do this by adding a simple entry to a simple PeopleOnline table whenever someone logs in to my site. If they manually log OUT of the site, I have no problem deleting them from the PeopleOnline table. But if they just close the browser, I was assuming I'd have to use the Session_End() event in Global.asax even though I know that this will only occur once the...
0
9595
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
10604
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9177
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
6870
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
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3837
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3005
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.