Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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 November 15th, 2003, 07:27 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aadz5
Default Creating Sesions

Hi Guys,

how do you create a session for a person that has logged in into your website??

Thanks

Adz - Portsmouth Massive
__________________
Adz - Learning The J2EE Ways.
 
Old November 15th, 2003, 09:36 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You actually don't need to create a session for a user. ASP.Net creates the session when the first request is received from the client. So the session is already there and ready for you to use. All you need to do is add things to it.

To save a value in the session collection you can do this:

Session.Item("mySessionValueKey") = myValue

One important thing to know about using the session object in ASP.Net is that you have to check to see that an item exists before you try to access it. For example, let's say you need to keep track of a userID. Wherever you need to get it from the session, you need to check for it's existence.

If Not Session.Item("userID") Is Nothing
    'Do something with it here
End If

Also, keep in mind that when you request something from the session collection, it is returned as an object so you will have to convert it to the right data type. For example, if we wanted to get our userID which is an integer, we'd do this:

userID = CType(Session.Item("userID"), Integer)

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 16th, 2003, 09:42 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aadz5
Default

Thanks for your help

Adz - Portsmouth Massive
 
Old December 17th, 2003, 11:23 AM
Authorized User
 
Join Date: Dec 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to AyatKh
Default

Hi, I'm new to ASP.net and I wanted to use the Session object and I wanted to save a class with one property in it.
Could you please tell me the difference between :
Session.Add("FileObj"), FileObj) AND
Session("FileObj") = FileObj

Thanks
Ayat

Quote:
quote:Originally posted by aadz5
 Hi Guys,

how do you create a session for a person that has logged in into your website??

Thanks

Adz - Portsmouth Massive
 
Old December 17th, 2003, 04:18 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

There is little difference between these two methods of adding items to the Session collection except perhaps that the actual "Add" method may return an error or throw an exception if you try to add a item with a key that already exists in the collection.

Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating New Database everest SQL Server 2005 2 July 10th, 2007 01:32 PM
Creating Menus Andrew_S ASP.NET 2.0 Basics 1 May 7th, 2006 12:58 PM
creating tooltips? Hannibal Javascript How-To 6 April 27th, 2006 09:20 AM
Creating Files xchemicalbeatz VB.NET 2002/2003 Basics 6 April 14th, 2005 08:24 AM





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