Frinavale 9,735
Recognized Expert Moderator Expert
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.e xe). 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: -
Private Sub btn_button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_button1.Click
-
Session("userName") = txt_userName.Text
-
End Sub
-
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: -
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
Dim userName as String = Session("userName")
-
lbl_welcome.Text= "Welcome to working with Sessions " + userName + "!"
-
End Sub
-
13 35981
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
Frinavale 9,735
Recognized Expert Moderator Expert
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.Redire ct("nameOfNextP age.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
There are so many ways to pass the information from one web page to another.
1)QueryString
2)Session - 3 modes(Statemode ,sqlserver,inme mory) - 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.
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,inme mory) - 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.
Plater 7,872
Recognized Expert Expert
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.
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
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.
Frinavale 9,735
Recognized Expert Moderator Expert
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
There are so many ways to pass the information from one web page to another.
1)QueryString
2)Session - 3 modes(Statemode ,sqlserver,inme mory) - 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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 (aspx) is not
recognized by FrontPage - is there another tool that
designers like and allows to work directly on aspx
pages ?
|
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 page. Once the user logs in then they are directed to the appropriate link.
So for all 3 links they all go to a login page, but each link must pass information to the login in page, specifically the page to go to after login takes place.
--
Paul G...
|
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 advantages/disadvantages of each, or any
good/bad experience using one against the others.
Thanks
|
by: Marcelo |
last post by:
Any suggestion?
Thanks
Marcelo
|
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 vb.net form? I'm not sure
where to begin at this stage. The only thing I can see, is that when
my asp page code parses the information that I need, I'll need to write
that information to a database or a file then have something in my
vb.net...
| |
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 used the following in the criteria section of the query for the operators to refine the search . However, the operators do not always remember how the clients name appears in the DB and we get several failed queries. To correct this, I created a form...
|
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 Window A and
Window B. A is the main application and opens a popup window called B.
I then have a button in B that needs to pass control back to Window A
with some data in the URL and then close itself. Is this possible? If
so.. how?
|
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.
regards,
joseph
|
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.
Here is a newbie mistake that I found myself doing (as a newbie), and
that even a master programmer, the guru of this forum, Jon Skeet,
missed! (He knows this I'm sure, but just didn't think this was my
problem; LOL, I am needling him)
If...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |