Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Force login after browser closed

Status
Not open for further replies.

Waynest

Programmer
Jun 22, 2000
321
0
0
GB
asp.net 2, sql 2000

Hi

I would like to change the behaviour of my web app so that if the user closes the browser window & reopens it he has to login again. Currently his last page is displayed again which isn't the behaviour I want.

Is this something I can control via web.config?

TIA
 
Nope. How does your server know that the user closed their browser?

The only thing you could do is have cookies that automatically expire and log the user in based on whether the cookie exists.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Or you could use Javascript to make an AJAX call to a page that ends the session in response to the window.onunload event. I've used the following code which allows you to determine if the user has closed the browser...

Code:
window.onunload = function() {
	// The following test determines if the window has closed
	var top = self.screenTop;
	if (top > 9000) {
		// Make an AJAX call here to log out the user
	}
}
 
tsctom, I have used the onunload function before as well, however, only IE recognizes it.
 
Good point. How about using onbeforeunload instead? I think Firefox recognises that one. My code above may need to be changed though because onbeforeunload works differently (from memory).
 
Sorry I was thinking of the onbeforeunload event. The onunload should work.

Sorry about the confusion.
 
Better than nothing (which is the alternative) though!
 
Better than nothing
I think it's a lot worse. What's the point in having a function that sometimes works?

You're better off going down the expiring cookie route if you want a consistent approach.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top