Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 August 26th, 2004, 10:52 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default Removing Session variables

I have a page where I pass in Date values in Session variables. I use them to generate a report on the page. If I just copy the value into the viewstate and remove from the session, it works fine unless I refresh the page.

I am currently not using the viewstate, and keep the value in the session. This works fine (refreshes are ok), but I want to remove these values from the Session when I'm done with them - when the user leaves the page. How is this done? I don't want unnecessary Session values using up memory until they log/time out.

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old August 26th, 2004, 11:02 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I believe the session has a remove method, but if not, do:

Session("Value") = Nothing

Or Session.Abandon()

Brian
 
Old August 26th, 2004, 11:25 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I was using that approach, but when I refreshed the page, I lost my values (and subsequently broke my code)

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old August 30th, 2004, 07:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Isn't that the idea for removing session values, to lose the values? Could you post any code and let me know what your approach is?

Brian
 
Old August 30th, 2004, 09:03 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Brian-

My code goes like this (in the Page_Load procedure)

Code:
If Not Page.IsPostBack Then
   viewstate("Date1") = Session("Date1")
   viewstate("Date2") = Session("Date2")
   'Clean up session
   Session.Remove("Date1")
   Session.Remove("Date2")

   obj.StartDate = CDate(viewstate("Date1"))
   obj.EndDate = CDate(viewstate("Date2"))

   results = obj.GetReportData
End If
Postbacks are ok, but when I refresh the page, the date values are lost. I get the "SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM." error.

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old August 30th, 2004, 09:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Clean up your sessions in the global.asax:

protected void Session_End(Object sender, EventArgs e)
        {

        }



 
Old August 30th, 2004, 09:19 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Stu-

Is it a question of where I remove the Session variables or when?

If I implement a procedure in the Session_End procedure of global.aspx, I have to wait until their Session times out or until they log out (I explicitly abandon the Session in the log out procedures). I want to only keep these values in the Session so that I could pass them from the previous page.

I don't like to keep values in Session once they aren't needed anymore in order to free up the resources.

-Colonel

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old August 30th, 2004, 09:47 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

FYI, I also tried this:
Code:
Private Sub CleanSession(ByVal sender As System.Object, ByVal e As EventArgs) Handles MyBase.Unload
        'Clean up session
        Session.Remove("Date1")
        Session.Remove("Date2")
End Sub
With the same error.

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old August 30th, 2004, 02:36 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Are you storing these values so that they survive page redirects and such (spanning across multiple pages)? If so, if the session doesn't work, you can use the cache... may be more efficient, and easier to use. It has an application-level scope; however, there are tricks to make it unique to a user.

Brian
 
Old August 31st, 2004, 07:12 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm using the session to avoid bloating my querystring.

The scenario is a report: On the first page the user selects the criteria for the report, the second page displays the report data. I use the session values to pass 2 dates and a list of integers from the first page to the second.

I have a band-aid solution that involves a try-catch block. If the date values are lost, the user is redirected to the criteria (first) page.

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Session Variables testsubject Visual Studio 2005 8 March 8th, 2006 04:26 PM
Is it possible for me using session variables into see07 ASP.NET 1.x and 2.0 Application Design 4 March 9th, 2005 07:46 PM
Removing a stateful session bean from client code noman77 J2EE 0 February 24th, 2005 01:55 AM
Session Variables - help? Annoyamouse BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 11 August 31st, 2004 03:56 PM
Session Variables flesh_god Dreamweaver (all versions) 7 November 11th, 2003 05:52 PM





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