Asp.net Study Notes: application, session, Server

Source: Internet
Author: User

During this period of time, I used my spare time to study ASP. NET again. I just learned three ASP. NET objects: application, server, and session. I think it is useful to take notes first, so as to facilitate future query and use. By the way, I can also get a better impression. Because the understanding varies from person to person, please refer to the official msdn document for detailed explanations of objects in this article.

1. Application Object

Personal Understanding: Applications and objects are generated when we run the program. The application stores data with key-value pairs and can understand the application object as a collection of objects.

Class: httpapplicationstate Enabled

Msdn official: global information sharing between multiple sessions and requests in ASP. NET Applications

ASP. NET applications are the sum of all files, pages, handlers, modules, and code in a virtual directory on a single web server and its subdirectories.

A single instance of the httpapplicationstate class is created when the client requests any URL resource from a specific virtual directory of an ASP. NET application for the first time. A separate instance must be created for each ASP. NET application on the Web server. Then, the reference to each instance is made public through the internal application object.

The application status is not shared in the network farm (the application is hosted by multiple servers) or in the network farm (the application is hosted by multiple processes on the same computer.

How to Use: If you want to use an application, you can first add an asax file to initialize application-level or session-level variables. You can directly add the asax file in vs2008, but you have already created an ASP. netweb application in vs2003. Global. asax in vs20003 exists in the form of classes, while global. asax in vs2008 exists in the form of script files (personal understanding ). After the creation, we will see the following events in the global file:

1. Void application_start (Object sender, eventargs E)
{
// Code that runs when the application starts

}

2. Void application_end (Object sender, eventargs E)
{
// Code that runs when the application is closed

}

3. Void application_error (Object sender, eventargs E)
{
// Code that runs when an unhandled error occurs

}

4. Void session_start (Object sender, eventargs E)
{
// The code that runs when the new session starts

}

5. Void session_end (Object sender, eventargs E)
{
// The code that runs when the session ends.
// Note: Only the sessionstate mode in the web. config file is set
// The session_end event is triggered only when inproc is used. If the session Mode
// If it is set to StateServer or sqlserver, this event is not triggered.

}

Ii. Session Object

Personal Understanding: stores user information. Session: the client (browser) wants the server to send a request, and the server returns the response to the client. This process can be understood as a session)

Class: httpsessionstate

Official msdn: provides access to session Status values and session-level settings and TTL management methods. For more information, see msdn ASP. NET session Status

Common attributes: sessionid (unique user session identifier) Timeout (user time-out) lcid (local identifier) count (number of items in session state)

Common events: void session_start (Object sender, eventargs E) and void session_end (Object sender, eventargs E)

Iii. Server Object

Personal Understanding: get information about the server you are requesting

Class: httpserverutility

Official msdn: Provides the Helper method for processing Web requests.

Common attribute: scrtipttimeout machinename

Common Methods: Execute transfer htmlencode, urlencode, and mappath

Execute: execute another page on the server side. After the execution is complete, return the result to the current page.

Transfer: similar to response. Redirect ()

Htmlencode: HTML Tag output in plain text format

Urlencode: Process special characters that are contained when parameters are passed through URLs

& Variable Separator

 

Knowledge point:

1. application objects are application-level and shared by all users, while sessions are user-level. Other users cannot access sessions of other users.

2. Apollo and session are both set objects of key-value pairs.

3. the timeout value for session disconnection or destruction is generally 20 minutes. You can set the timeout value in the session_start event. The minimum value is 1 (1 minute ). It should also be noted that the session is disconnected or destroyed if you close the browser, but the timeout of your session times out or closes the World Wide Web Hing service, or your machine shuts down normally.

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.