Object Description in ASP. NET

Source: Internet
Author: User

Several objects in asp.net:

1. Request: You can access personal or process information on the Request web page.

2. Response: provides a method to accurately control how a Response is sent back to the person sending the request

3. Server: provides a series of useful Web-related utilities.

4. Application: provides a useful Web site storage location for frequently used information

5. Session: stores information for each user's Session.

Object · Request in ASP. NET

Request can access personal or process information on the Request web page. The Request object can effectively transmit messages to us from a personal Web browser.

Two useful attributes are:

Cookies: This attribute allows you to view the cookies that visitors previously stored on this site.

QueryString: returns any parameters transmitted to the page using GET.

Objects in ASP. NET · Response

Response provides a method to accurately control how a Response is sent back to the person sending the request. The Response object can access the http Response that will be sent back to the Web browser.

Common attributes:

1. Redirect: It redirects the user to another page

2. Write: Write a string to an html stream.

Server

Object · Server in ASP. NET

Provides a series of useful Web-related utilities.

Common attributes:

MapPath: this property has a virtual path Parameter

For example, MapPath ("/webapp/myfile. aspx") returns the exact location of the file on the physical disk.

Status processing:

Including Application, Session, and Cookies

Pay attention to stateful scopes, status storage locations, and status changes.

Object · Application in ASP. NET

Application provides a useful Web site storage location for frequently used information

The information in Application can be accessed by all pages of the website.

Initial Configuration of Application:

Configure the initial status when the application starts, and configure it in Global. asax

 
 
  1. protected void Application_Start(Object sender, EventArgs e)  
  2.  
  3.          {  
  4.  
  5.               Application["UserCount"] = 0;  
  6.  
  7.          }  
  8.  

Use Lock and Unlock to avoid modifying the status of both pages.

 
 
  1. Application.Lock();  
  2.  
  3. Application["UserCount"] = (int)Application["UserCount"]+1;  
  4.  
  5. Application.UnLock();  

Application description:

1. It is used for frequently used data. If it is used only occasionally, information can be stored in disk files. In most cases, the web. config file can complete this task.

2. The Application object is a collection object, which can store objects in addition to text information.

3. If the site has a large amount of traffic at the beginning, use the Web. config file instead of the Application state.

Object · Session in ASP. NET

It stores information for each user's session. The default timeout value is 20 minutes. After the user closes the webpage, it automatically ends.

Common attributes:

Abandon (): This method ends the current session and clarifies all information in the session.

Clear (): clears all information in the session and does not end the session.

IsNewSession: If a painting is created when a user accesses the current page, this attribute returns true. This attribute is useful when some data needs to be used to initialize a session before using the session.

TimeOut: This attribute is used to obtain and set the idle time in minutes before the session ends. The default time is 20 minutes.

 
 
  1. if (Session["test"]==null)  
  2.  
  3. {  
  4.  
  5.      Session["test"] = 1;  
  6.  
  7. }  
  8.  
  9. else 
  10.  
  11. {  
  12.  
  13.      Session["test"] = (int)Session["test"]+1;  
  14.  
  15. }  
  16.  

Session Description:

1. stored on the Web server,

2. The actual information is related to each visitor.

3. It is an object set that can store objects.

4. Do not store things that are not often used in sessions, or store a large number of things in sessions.

Cookies

Stores small pieces of information related to each user, usually related to websites. Stored on the user's hard disk, generally with a longer term than the Session.

Cookie survival settings

 
 
  1. DateTime dt = DateTime. Now;
  2.  
  3. TimeSpan timeSpan =NewTimeSpan (30, 0, 0 );// 30 days 
  4.  
  5. If(Request. Cookies ["Test"]! =Null)
  6.  
  7. {
  8.  
  9. Request. Cookies ["Test"]. Expires = dt. Add (timeSpan );
  10.  
  11. }
  12.  
  13. Cookies
  14.  
  15. If(Request. Cookies ["Test"] =Null)
  16.  
  17. {
  18.  
  19. IntI = 1;
  20.  
  21. HttpCookie c =NewHttpCookie ("Test");
  22.  
  23. C. Value ="1";
  24.  
  25. Request. Cookies. Add (c );
  26.  
  27. }
  28.  
  29. Else 
  30.  
  31. {
  32.  
  33. IntK = Convert. ToInt32 (Request. Cookies ["Test"]. Value) + 1;
  34.  
  35. Request. Cookies ["Test"]. Value = k. ToString ();
  36.  
  37. }
  38.  
  1. Principles and Applications of ASP. NET1.1 Verification Code Generation
  2. Static File Processing: ASP. NET1.1 and ASP. NET2.0 are different.
  3. Run the windows program (ASP. NET1.1) in ASP. NET)
  4. Modify the template class for asp. net1.1 Development
  5. Connect Oracle9i with ASP. NET (ASP. NET1.1)

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.