Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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
 
Old September 4th, 2009, 02:57 AM
Registered User
 
Join Date: Sep 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Regarding session expiration

Hello Imar.
I have read your book - Beginning ASP.NET 3.5 in C# and VB. I liked it very much and I got a large amount of knowledge on ASP.NET by reading this book. I have made a project on asp.net also.
However, I have one question which I know you can answer regarding session expiration in asp.net.
I want that a user login to my site and after login when he clicks on the back button of the browser, he will be redirected to the login page again and his session expires. How can I implement his in asp.net.
I hope you can answer me and if possible, please send me a small site which has this feature alongwith asp.net coding.

Thanking you

Reagrds

Rohit Saxena
INDIA
E-mail: [email protected]
 
Old September 4th, 2009, 04:34 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Good to hear you like the book.

I think you're mixing up two concepts here: Caching and Sessions. The problem you're describing is not related to sessions, but to caching. The previous page is cached by the browser so it's shown without another request to the server. To fix this, add the following line to the page you want to expire:
Code:
 
Response.Cache.SetCacheability(HttpCacheability.NoCache)
This tells the browser not to cache the page, and to request it from the server again instead.
You may have to clear your browser's cache the first time to make this work.

If it still doesn't work, try a combination of the following:

Code:
 
Response.Expires = -1500
Response.AddHeader("Pragma", "no-cache") 
Response.AddHeader("cache-control", "private")
Response.CacheControl = "no-cache"
Response.Cache.SetExpires(DateTime.Now.Date.AddDays(-100))
Response.Cache.SetNoServerCaching()
Response.ExpiresAbsolute = DateTime.Now.AddDays(-100)
Response.Cache.SetNoStore()
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Cache.SetValidUntilExpires(False)
You probably don't need them, but I've seen people report success with various combinations of these cache settings. YMMV.

Hope this helps,

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old November 16th, 2009, 11:46 AM
Registered User
 
Join Date: Nov 2009
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Master Page?

I've been banging my head against my desk for two days while trying to get this to work. After successful logout, I don't want users to be able to preview the expired page using the back button. Thanks for posting this code.. I will try it and post back with results.

Also, if I add this code to my master page, I'm assuming it will apply to any page tied to that master page. Is this correct?

Thanks,

Jeff
 
Old November 17th, 2009, 06:04 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
Also, if I add this code to my master page, I'm assuming it will apply to any page tied to that master page. Is this correct?
Yep, that's correct.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old November 19th, 2009, 05:27 PM
Registered User
 
Join Date: Nov 2009
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default That worked!

Imar,

I added all of the code you provided and it seems to have done the trick. Thanks again.

Jeff





Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirecting to a different page during session expiration aldwinenriquez ASP.NET 2.0 Professional 3 April 16th, 2009 09:58 PM
Setting Expiration Dates of Emails cvn6565 ASP.NET 2.0 Professional 0 October 16th, 2006 02:48 PM
Session expiration manoj_k79 Classic ASP Basics 1 October 13th, 2006 07:19 AM
Page Expiration? Thagi ASP.NET 1.x and 2.0 Application Design 2 March 7th, 2006 12:12 AM
Validate Expiration date mariakovacs Classic ASP Basics 4 January 26th, 2004 12:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.