 |
| Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

November 5th, 2003, 08:30 AM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Implementing "Logout"
Hi friends
How do I implement "Logout " in ASP ?please help with code.
Praveen.
|
|

November 5th, 2003, 08:37 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Well, it all depends on how you implemented Login.... ;)
If you are using Sessions to keep track of logged in users, a page called logout.asp with the following code would work:
Code:
<%
Session.Abandon()
Response.Redirect("/default.asp")
%>
This destroys the current Session object for the user and then redirects him / her to the homepage. You can provide a link to the logout.asp page from anywhere within your site.
If that doesn't help, describe your login mechanism in more detail.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

November 5th, 2003, 11:35 PM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi
I have not implemented any session ,basically the login verifies the username/password from the database and redirects the user to the page.Now how do I implement Logout?
Thank you
Praveen
|
|

November 6th, 2003, 04:05 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Well, it still depends on how you implemented the login... ;)
Checking the username and password against a database is only the first part. How do you save the state of the logged in user? That is, where do you keep something like a UserLoggedIn flag? In a cookie? Somewhere else? Do you check the username and password on every page?
If you don't store this state anywhere, logout is automatic. Because the Web is stateless, it will forget about the user after a page has been requested. This means that the user will have to log in again when they request another protected page, unless your site "remembers" somewhere that they have logged in already.
Does this make sense?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

November 6th, 2003, 04:43 AM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi
The login does not have any mechanism to store the details of the user.it taked the username/password from the user and then opens the database and then if correct than redirects the user to the home page else gives a password error message.now I want to implement a logout which would clear the cache (or page expires) and force the user to re login after pressing the Logout.pls give code
Thankz
praveen
|
|

November 6th, 2003, 04:55 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Right, so you're not really after a "logout" feature, but you need to expire the page, right?
If you don't store login information, the user will not be really logged in. They have to supply a username and password to view the page, and that's it. If you need to expire the page so your users have to provide their username and password again, add the following code to the top of your page:
Code:
<%Response.ExpiresAbsolute = #1/1/1980#
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control", "private, no-cache, must-revalidate"
%>
This makes sure that the page is not cached, and has to be requested again from the server. This will force your users to fill in their username and password again.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

November 6th, 2003, 06:04 AM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi
Thanks , Is it possible that only when I press the logout button all the cache is then cleared?so the user has to relogin only if he had pressed the "logout" button
praveen
|
|

November 6th, 2003, 06:18 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
No. A page either expires (using the code I showed you) or does not expire.
You'll need to create a login mechanism that keeps track of the logged in user. You can use Sessions or Cookies for that. When the user logs out by pressing the button, you need to clear the Session variable. When the user tries to view the page again, this Session variable doesn't exist anymore, so your users need to log in again.
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

November 6th, 2003, 06:26 AM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi
thankz, Now how do i implement login/logout using sessions .plz help
praveen
|
|

November 6th, 2003, 06:47 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Try this:
http://www.google.com/search?hl=en&i...n+sessions+asp
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|
 |