Solved

session object asp.net/vb.net

Posted on 2008-10-09
10
1,196 Views
Last Modified: 2013-11-07
What is session object and how it is used. in asp.net /vb.net to display the result on the third page.
0
Comment
Question by:mahmood_786
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 8

Expert Comment

by:rodmjay
ID: 22680903
you can add something to the session like this

Page.Session.Add("key", value)

or normally you just do

Session("key") = value

and then to get the value back on another page you can just do

CType(MyObjectType, Session("key"))

professionals usually do something like htis

dim x as object = Session("key")
if x isnot nothing
 ' cast to your type
  CType(MyObjectType, Session("key"))
end if
0
 

Author Comment

by:mahmood_786
ID: 22683411
what is key and what is value in here i do not understand
0
 
LVL 5

Expert Comment

by:harwantgrewal
ID: 22683626
Hi mahood_786
Before I explain anyting on that I wanted to know you .NET level or in general programming level. As it will help me in explaing you in that way.

Thanks
Harry
0
 

Assisted Solution

by:mrleowashingtonII
mrleowashingtonII earned 200 total points
ID: 22688620
The Key value is a variable that you assign. For example

Session("User")=login1.username.value
You can now call that session variable from within your ASP.Net pages by using the

myvariable=CType(Session("user"), String)

You can then do whatever you need to do based on the user for that pparticular web page.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Expert Comment

by:mrleowashingtonII
ID: 22689631
If you need further clarification:

The first Line  in my comment would go into a login page for example. Now, the values is stored as a session key, (Like a variable that exist for the length of the session).

When the user moves from page to page, you must put in the second line (or something similar, ie open a data set based on the value in the session, or display certain values in a listbox.

You can assign the value to nearly anything, as long as you use it in the format shown behind the equal sign.
0
 
LVL 5

Expert Comment

by:harwantgrewal
ID: 22691348
Hi mahmood_786

I let try to explain Sessions in details then you can view code for rodmjay which will help you to use session in VB.NET.

In Any programming you have to use variables now each variable has a scope, which means what is the boundaries of each variable. You have private, public, Global. And each type name make sense. Now Session is a container of different variable which are kind of Global, when I say kind of means its available to every page in your application in the same browser. Another type of Container for global variable is Application which are available to you application irrespective of browser.

Now when I mentioned Session are like container which holds all the session variables not if you want to get any kind of variable out of this container then you need some key attached to every variable. Its like you have so many doors and you need key attached to each door to open and get the value :) so when you want to get the variable value you provide key to session variable and it will get or set value to that key.
Example
To Set Value
Session("hiword") = "Hello"
To Get Value
Dim hi as String
hi = Session("hiword");

I hope that will make you understand what are sessions
0
 

Author Comment

by:mahmood_786
ID: 22698557
harwant that was great explaination,so the above code will give the value of hello where ever it is called on the application pages?
0
 
LVL 5

Expert Comment

by:harwantgrewal
ID: 22698638
yes that's true you will get hello as results on every page provided it's been requested by the same browser
Harry
0
 
LVL 5

Accepted Solution

by:
harwantgrewal earned 300 total points
ID: 22698987
Just a bit more on Sessions.
Basicly the sessions are stored on the server memory and when you open a browser a session ID is generated by browser whenever you try to create a session variable and then browser sends this session ID on each request made by the browser. And server session technology is so smart that get get the session container for your browser with that ID. And basically this session ID is stored as a cookie in the browser and if you disable the cookies you have to sepcify in your application that you want the application sessions to be cookie less, then you application automatically convertes all the URL to attach session ID in the string, and thats how you can get your session object.

Harry
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now