2017-5-22 ASP six large built-in objects

Source: Internet
Author: User
Tags server memory

ASP built-in object: Provides an inline object that makes it easier for users to gather information sent through a browser request, respond to a browser, and store user information, such as user preferences.

1.Request ---Get Request object

Gets the object passed through the address bar.

String AAA = request["Key"]; Key must be the same as the object name of the value passed

2.Response ---response Request object

Response.Redirect ("Newly opened URL? Aa=key"); Response.Redirect ("Newly opened URL? aa=" +key)

Address bar value/url value/querystring value-added advantage: No server memory, confidentiality check, the length of transmission is limited

? Aa=key the object to be passed can only be refreshed on the original page and cannot open a new tab

Response.Write ("string"); ---output string to the top of the page, string can write JS code, open a new URL

3.Session

Advantages: 1. Storage on the server, consumes 2. Transfer Speed 3. Do not abuse, easy overflow

Life cycle: 20 minutes, each request will refresh this time, if the browser is closed, the session will be disconnected from the link

Session can store object type

Session Page Pass Value:

string aa = TextBox1.Text;        session["zz"] = AA;        Response.Redirect ("bb.aspx");

Pages Received:

Label1.Text = session["zz"]. ToString ();

To pass an instantiated object:

protected void Page_Load (object sender, EventArgs e)    {        Button1.Click + = button1_click;          }    void Button1_Click (object sender, EventArgs e)    {        users u = new Users ();        U.username = "Xiao Ming";        U.sex = "male";        session["zz"] = u;        Response.Redirect ("bb.aspx");    }

Pages Received:

  

Users u = new users ();        U = session["zz"] as Users;        Label1.Text = U.username + u.sex;

4.Cookie

The cookie is identical to the session and is different: Cookies are stored on the client's

The pros and cons of both:

Session is secure, but consumes server memory, Cookies, and does not consume server memory, exists on the client, but is likely to be accessed

The cookie is judged not to be empty:

if (request.cookies["AA"]!=null) {}---directly determine if the received value is not NULL

To set persistent cookies:

String u = TextBox1.Text;

response.cookies["AA"]. Value =u;

response.cookies["AA"]. Expires = DateTime.Now.AddDays (3);----Set Cooki duration 3 days, different browsers have their own cooki, regardless of the time saved, just save under the current browser

Exit of the Cookie:

Page Pass Value:

protected void Page_Load (object sender, EventArgs e)    {        Button1.Click + = button1_click;          }    void Button1_Click (object sender, EventArgs e)    {        string u = TextBox1.Text;        response.cookies["ZZ"]. Value = u;        Response.Redirect ("bb.aspx");    }

Pages Received:

  

protected void Page_Load (object sender, EventArgs e)    {                string u = request.cookies["zz"]. Value;        Label1.Text = u;    }

5, Application:

  Global public variable Group

Storage location: Server

Features: All access users are access to the same variable, but as long as the server does not stop, the variable exists in the server's memory, do not use the loop to create a large number of application objects, may be created

into a server crash.

Life cycle: Permanent, as long as the server does not stop

How to use: Same as session

6, ViewState:

Used to record some state of a page, like a human case, such as when a commit is executed, the Web page can retain some text boxes that have been entered instead of emptying

In WebForm, Microsoft has already done this for us, bringing this functionality to our own.



2017-5-22 ASP Six large built-in objects

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.