开发者

What is the use of Session in web application/ASP.Net?

I am new to web technology, I 开发者_运维问答am wondering about the use of Session. What is the basic use of Session, is it only used for saving soma data or it has something else ?


Session is all about storing data across page requests. One of the downsides of HTTP (the core protocol of web applications) is that it doesn't store anything from one page request to another; you have to build all that in yourself. There are generally two places to store data: the browser or the server, and sessions are server based.

A session starts when you first log into a system and continues for as long as you stay on the site. When you close your browser (or perhaps log off, depending upon how it's configured) your session ends (there's usually a delay, so it ends after X minutes without activity). If you, as a web site developer, need to store some information about the user (name, address, shopping cart, etc), then session is often used as a place for that storage.Generally the reason for storing data in the session is for performance; reading from a database is relatively slow (compared to other actions a web page performs), so if you read the data once then store it in the session, you can make your site faster. The downside is that the more data you store in the session, the more memory you use on the server, so it's a trade-off between performance and memory usage. In the above code, the session is being used to store some user details (name, email, etc). If those don't exist in the session when read, an empty string is returned.


Session is for storing user-specific data for a limited period of time - namely, a single session of activity:

[A] communication session is a semi-permanent interactive information exchange between communicating devices that is established at a certain time and torn down at a later time.

This is deliberately vague, since the details of what makes a "session" can be somewhat different from application to application depending on how it is used. For a typical web application, a user's session begins the first time they visit the site, and ends some time after the user has no longer made any requests, and is presumed to have left the site. Things like a shopping cart, which are user-specific, might go in the session object, since it follows the same user across requests. In ASP.NET, the Session is described:

ASP.NET session state identifies requests from the same browser during a limited time window as a session, and provides a way to persist variable values for the duration of that session.


Session is use for storing some data for limited priod of time is have use to send some information one page to other page without data base connectivity like:

1st page:

Session["valiable name"] = textbox1.Text;

2nd page:

Lable.Text = Session["valiable name"].ToString();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜