473,378 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,378 developers and data experts.

Sessions - How To Pass Information Between Web Pages

Frinavale
9,735 Expert Mod 8TB
One of the most fundamental topics in web design is understanding how to pass information collected on one web page to another web page. There are many different ways you could do this: Cookies, Database... However, I'm going to cover how to use Sessions.

Sessions are used to store information in order to use it during later page requests or in other web pages in a web application. By default Cookies are used to identify which session belongs to which browser. There is an option that you can set in your web.config file to use Cookieless Sessions; however you should keep in mind that for most web applications the Session ID should be kept private and when using Cookieless Sessions the Session ID is displayed in the query string.

In .NET there are three session states: InProc, StateServer, and SQLServer.
By default web applications are set up to use InProc.


Where are Sessions stored?
InProc
The session is kept as live objects on web server (aspnet_wp.exe). It is stored in memory and is the fastest out of the three options; however, you should keep in mind that the more data you store in session, the more memory on the web server is consumed. This could affect the performance of your applications running on the web server. Also keep in mind that you cannot use InProc sessions in a web garden for many reasons I'm not going to get into.

StateServer
The session is serialized and stored in memory in a separate process (aspnet_state.exe). State Server can run on another machine, whereas InProc is specific to the machine the website is running on. You should keep in mind that the cost of serialization/deserialization of the session can affect performance if you're storing lots of objects.

SQLServer
The session is serialized and stored in a table in an SQL server. It requires you have a database available and you should think about how you are going to secure the connection to the database. This is the slowest of the three options but is required in order to store persistent data.

How do I use Sessions in my web application

It's really quite simple.
In the following example I use VB.NET to store the text value (userName) of a text box in session during a button click:
Expand|Select|Wrap|Line Numbers
  1.  Private Sub btn_button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_button1.Click
  2.    Session("userName") = txt_userName.Text
  3. End Sub
  4.  
In the following example I use VB.NET to display the text value (userName) stored session. This can be used on another web page within the web application:
Expand|Select|Wrap|Line Numbers
  1.  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.      Dim userName as String = Session("userName")
  3.      lbl_welcome.Text= "Welcome to working with Sessions " + userName + "!"
  4. End Sub
  5.  
May 9 '07 #1
13 35856
Hello Frinavale

Iam trying to implement the example "How do I use Sessions in my web application"
I am new to Development.
Would you have the complete tutorial for it?

Thank You
Melissa
May 15 '07 #2
Frinavale
9,735 Expert Mod 8TB
Hello Frinavale

Iam trying to implement the example "How do I use Sessions in my web application"
I am new to Development.
Would you have the complete tutorial for it?

Thank You
Melissa

Sorry I don't have a complete tutorial for it because I didn't write this article based on any tutorials.

You could try to create an web application with two aspx web pages.

The first page should have a text box and a button.
It should have the server side code that stores the text found in the text box into session on the button click event. Once the information is stored in Session, redirect the user to the next web page (use Response.Redirect("nameOfNextPage.aspx") to transfer them)

On the second page, retrieve the information from session and display it into a label in the Page_Load() method.

It's pretty easy to use. If you still need more help try looking up Sessions on the MSDN Library, there may be a tutorial there. Or you could just keep asking for help here on theScripts.

Cheers! :)

-Frinny
May 22 '07 #3
There are so many ways to pass the information from one web page to another.

1)QueryString
2)Session - 3 modes(Statemode,sqlserver,inmemory) - load on sever if the data is too large.
3)Application - Application wise globally.
4)Cookie - useful but risky. depends on client browser either it supports the cookie or not.

There are also facility for ViewState--maintaining the state for one page.

ViewState - encrypted and good. but if it contains the large data the perfiomance goes down.


HiidenFields and hiddenframes are also there.
Aug 9 '07 #4
Yes, agree.
I always also pass informations in QueryString.
It seems to be more difficult but I think its better than to store informations in sessions objects.


There are so many ways to pass the information from one web page to another.

1)QueryString
2)Session - 3 modes(Statemode,sqlserver,inmemory) - load on sever if the data is too large.
3)Application - Application wise globally.
4)Cookie - useful but risky. depends on client browser either it supports the cookie or not.

There are also facility for ViewState--maintaining the state for one page.

ViewState - encrypted and good. but if it contains the large data the perfiomance goes down.


HiidenFields and hiddenframes are also there.
Sep 4 '07 #5
Plater
7,872 Expert 4TB
Yes, agree.
I always also pass informations in QueryString.
It seems to be more difficult but I think its better than to store informations in sessions objects.
QueryString is visible to the user and any thirdparties watching and is very easy to see since it's part of the URL. Session objects do not expose that information to the outside.
It's all just subtle differences in what you need.
Sep 4 '07 #6
Hi Everybody,

Well passing information from one page to another is something that we use quite often..and we need it always.

Well i cannot tell you exactly and the proper technical reason for not using Session Variables. Its not considered to be the best practice.

Yes there are some situation where you cannot avoid it at all. But then i believe we are talking about something more general which we will use in many pages. Passing of Data.

Well Querystring is the best practice for passing data.
Now as you have mentioned above, about the URL is displayed and the client or User can see what you are passing, which is not good if he sees, plus it is open to hackers. !!!

Well in that case, you should use HTTP Handler or HTTP modules.
It hides your physical URL and passing dummy one..

You can go to this link which covers the whole topic.

http://msdn2.microsoft.com/en-us/library/ms972974.aspx

I hope it helps you guys...i also learnt from here ... :)

Cheers

mady
Sep 21 '07 #7
Mady pointed out the issue of passing data via query strings (particularly usernames and passwords). The military was horrified when they found out the web page we were designing was going to pass data using query strings, and absolutely forbade it. When wanted to use session variables but since our site was a combination of some of the old classic ASP pages as well as ASP.net pages it was not possible to pass Session variables across the boundary. What we had to do was to pass the data into a database on the ASP side and then read it out of the database on the ASP.net side. This required use to store a connection string in a config file that would be available to both session on_start events, and limit the connection string to access only to that one table and that one database. The stored procedure that read back the data to the ASP.Net side would also clear that data out of the table. When also had the issue of passing objects and collections containing data from one page to another. This would not have been possible with query strings, but it was possible with Session variables.
Jan 9 '08 #8
Frinavale
9,735 Expert Mod 8TB
Thanks for that bit of information Joeller, I'm sure it'll help a lot of people facing the same problem. It's a nice solution :)

-Frinny
Jan 9 '08 #9
There are so many ways to pass the information from one web page to another.

1)QueryString
2)Session - 3 modes(Statemode,sqlserver,inmemory) - load on sever if the data is too large.
3)Application - Application wise globally.
4)Cookie - useful but risky. depends on client browser either it supports the cookie or not.

There are also facility for ViewState--maintaining the state for one page.

ViewState - encrypted and good. but if it contains the large data the perfiomance goes down.


HiidenFields and hiddenframes are also there.


i am aware of 1st 4 types u explaied including viewstate. but i have 1 doubt.
hiddenfield n hiddenframe r wh exactly , r they related to viewstate or something different, can u explain hiddenfield n hiddenframe more
Mar 5 '08 #10
Frinavale
9,735 Expert Mod 8TB
i am aware of 1st 4 types u explaied including viewstate. but i have 1 doubt.
hiddenfield n hiddenframe r wh exactly , r they related to viewstate or something different, can u explain hiddenfield n hiddenframe more
ViewState is used to remember the state of your ASP.NET controls.
Hidden Fields are html that hold temporary information for the page...it remembers information but not necessarily about an ASP.NET Control.

Hidden fields can be used to pass information between JavaScript and your .NET code. Eg. your JavaScript function does something and then stores the result into a hidden field, this filed can then be accessed by the server side code to do further calculations.

-Frinny
Mar 6 '08 #11
Ewan
18
Hi Frinavale, thanks for this info.
i had a doubt, i have i multiple users who would be accessing different records at the same time.
and if im using Session to pass the values as required, could this result in a slow performance for my web app. also is there any way to remove a session after the value is passed..
would this affect another user if his command(button click) tries to create the session again with the same name?
Feb 26 '11 #12
Frinavale
9,735 Expert Mod 8TB
If you have several users then you, and you are storing a lot of information in session, then you run the risk of using a lot of memory resources on the server computer. If you use more memory than is allocated to your website, then the web application process will be recycled.

I'm not sure about the effects of speed performance Session will have on your application; however, it is much faster than accessing a database every request. (Likewise storing things in ASP.NET's Cache is even faster).

Do some tests to determine what is best for your solution.


-Frinny
Feb 27 '11 #13
Thanks u sir i have don it.... love this forum
Dec 7 '11 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Carlo Marchesoni | last post by:
Ideally I would be able to give my aspx/ascx pages to a designer which makes them nice and since I'm, using code- behind he will not destroy my code. But unfortunately he says that this format...
9
by: Paul | last post by:
What I am trying to do is as follows. I have a page with 3 links,that direct the user to 3 different pages when selected after login. So all link selections will first direct the user to a login...
3
by: hugo.flores | last post by:
Hello all. I want to know what would be the best way to pass information between pages in ASP.NET? Querystring, seession variables, server transfer? If possible if anyone can list...
4
by: Marcelo | last post by:
Any suggestion? Thanks Marcelo
0
by: Robert Leroux | last post by:
Hello, I'm new at this part of vb.net development, but I am trying to find a way that I can take information that is contained in my asp page on my web server and pass that information to my...
10
by: sesling | last post by:
I have created a query that will pull information from our database for the operators. This query will pull in on average 50,000 records. The operators need to refine the search results. I have...
1
by: czuvich | last post by:
I am working in ASP.NET 1.1 and I was wondering if it was possible to have two different windows pass information between each other by the click of say a button. In other words, let's say I have...
1
by: Joseph Basil | last post by:
Hello , i am using lots of session in my projecct.therefore it affects the speed of the project .so can anyone hrlp me to transfer datas between pages without using session.pls help. ...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.