473,379 Members | 1,185 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,379 software developers and data experts.

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 4457
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*********************@g47g2000cwa.googlegro ups.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_EndRequest?

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.IsClientScriptBlockRegistered("clientScri pt"))
this.Page.RegisterClientScriptBlock("clientScript" ,strScript);
//This code goes in the Body html tag of each page in the application

<Body onunload="logoff('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=javascript>
<!--
var newwindow = ''
function logoff(url)
{
if (event.clientY < 0)
{
if (!newwindow.closed && newwindow.location)
{
newwindow.location.href = url;
}
else
{
newwindow=window.open(url,'Logout','height=150,wid th=100');
if (!newwindow.opener) newwindow.opener = 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)Session["strUserID"] == "")
{
Page.RegisterStartupScript("CloseScript","<script language=javascript>
window.close(); </script>");
}
else
{
lblMessage.Text = "<p align=center>Brands Manual<br><br>Logout
Successful<br><br><a
href='javascript: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.IsClientScriptBlockRegistered("clientScri pt"))
this.Page.RegisterClientScriptBlock("clientScript" ,strScript);
//This code goes in the Body html tag of each page in the application

<Body onunload="logoff('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=javascript>
<!--
var newwindow = ''
function logoff(url)
{
if (event.clientY < 0)
{
if (!newwindow.closed && newwindow.location)
{
newwindow.location.href = url;
}
else
{
newwindow=window.open(url,'Logout','height=150,wid th=100');
if (!newwindow.opener) newwindow.opener = 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)Session["strUserID"] == "")
{
Page.RegisterStartupScript("CloseScript","<script language=javascript>
window.close(); </script>");
}
else
{
lblMessage.Text = "<p align=center>Brands Manual<br><br>Logout
Successful<br><br><a
href='javascript: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.googlegr oups.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.IsClientScriptBlockRegistered("clientScri pt"))
this.Page.RegisterClientScriptBlock("clientScript" ,strScript);
//This code goes in the Body html tag of each page in the application

<Body onunload="logoff('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=javascript>
<!--
var newwindow = ''
function logoff(url)
{
if (event.clientY < 0)
{
if (!newwindow.closed && newwindow.location)
{
newwindow.location.href = url;
}
else
{
newwindow=window.open(url,'Logout','height=150,wid th=100');
if (!newwindow.opener) newwindow.opener = 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)Session["strUserID"] == "")
{
Page.RegisterStartupScript("CloseScript","<script language=javascript>
window.close(); </script>");
}
else
{
lblMessage.Text = "<p align=center>Brands Manual<br><br>Logout
Successful<br><br><a
href='javascript: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.cancelBubble = true;
return false;
}
var allowedBack = "INPUT,TEXTAREA,";
with(event)
{
//alert("keyCode: "+keyCode);
if(altLeft&&keyCode==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
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...
9
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; ...
2
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....
3
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...
4
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...
7
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...
8
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....
1
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...
12
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.