ASP. NET (3)-built-in object (2)

Source: Internet
Author: User

In the previous blog, we have learned in detail the Request object, Response object, and Application object, the remaining four Session objects, Server objects, Cache objects, and Cookie objects will be introduced in this blog.

Iv. Session Object

Unlike the Application object acting on the entire Application life cycle, the Session object only refers to the time when the visitor arrives at a specific page and leaves. Each user obtains a Session separately. Two independent users cannot share information through the Session variable, which is one of the shortcomings of the Session. Another disadvantage is that one user has a Session. When the number of users is large, the pressure on the system is also extremely high.

Of course, although there are some deficiencies, the Session object is one of the essential knowledge of ASP. NET developers. It has two common functions: Creating and reading sessions.

1. Create a Session object:

<Script runat = "server"> void Page_Load (object sender, EventArgs e) {// set the session variable "user_name" value Session ["user_name"] = "sld "; // display the successful Session setting information Response. write ("Session" user_name "assigned value") ;}</script>

2.ReadSessionObject:

Response.Write("user_name="+Session ["user_name"].ToString ());

So far, let's summarize the advantages of the Session object:

Store user information

Tracking and monitoring user information in sessions

Destroy objects after the session expires

V. Server objects

You can use the Server object to obtain various information on the Server, for example:



<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + signature + XO + signature/a94srNoaM8L3A + signature/M8L3A + signature + npdu6fm4bmp UN/Signature/ndctk/Signature + signature + LW2Li0z/ JXZWK3/logs/HIoc/gzazQxc + logs + downloads/downloads + downloads/O6zdKzw + bU2ldlYrf + zvHG97rN5K/logs + records + r/ j0tTA + Memory + 678 sbky/vQxc + rack/Rack + ioaM8L3A + rack + ICAgICAgICAgu + rack/Rack + rack/zo7o8L3A + rack "brush: java; "> <script runat =" server "> void Page_Load (object sender, EventArgs e) {// create an HttpCookie object instance MyCookie, the variable set is named user HttpCookie MyCookie = new HttpCookie ("user"); // value the variable user_name MyCookie ["user_name"] = "sld "; // set the Cookie expiration time to 365 days. expires = DateTime. today. addDays (365d); // Add Cookie Response. cookies. add (MyCookie); // display the Cookie creation success Response. write ("Cookie value already set");} </script>
2. Read Cookie objects:

Response.Write("user_name="+Request .Cookies ["user"]["user_name"]);

So far, seven built-in objects commonly used in ASP. NET are described separately, and their applications are learned through some simple examples. Of course, this is only the most basic knowledge. We need to continue to learn deeper application skills.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.