Server Object in ASP. NET and ASP. NETServer object

Source: Internet
Author: User

Server Object in ASP. NET and ASP. NETServer object

1. Common objects in asp.net:


Request: the server reads the information in the browser Request.

Response: send the information on the server to the browser.

Server: obtains information about the request Server.

Application: Application-level objects that can be shared by multiple users.

Session: the Session is started when you access the server through the web site.

The following figure shows that the published Server is a Server object and the web program running on the Server is an Application object. Each client's access to the web program is a Session.


2. Global. aspx

Initialize application-level variables and session-level variables,

Common events are in the Code:

Protected void Application_Start (object sender, EventArgs e) {// call the first asp.net page of the current application directory (or subdirectory) to define global variables, multi-User Sharing} protected void Session_Start (object sender, EventArgs e) {// triggered at the beginning of each new session} protected void Session_End (object sender, EventArgs e) {// triggered when the session ends} protected void Application_End (object sender, EventArgs e) {// triggered when the last session of the application ends, and also triggered when the internet Service Manager stops}

3. Server Object

Attribute: The MachineName user obtains the name of the server computer.

ScirptTimeout specifies the time period for the script to run on the server before it is terminated. The default shortest time is 90 s. This value is sufficient for script programs with simple logic and less activity content. However, when executing script programs with a large amount of activity content, it seems smaller. For example, the script program accessing the database must set a large ScriptTimeout attribute value. Otherwise, the script program cannot be executed normally.

Response. write ("Server machine name:" + Server. machineName); // server machine name Response. write ("Timeout:" + Server. scriptTimeout); // Timeout: seconds


Method:

1. Page Transfer

.Ececute ()

The current page transfers control to other pages. After other pages are executed, the results and control are transferred to the current page.

Purpose: You can write some common judgments on a single page and return them to the current page after execution. Go to the error page when an error occurs.

.Transfer ()

Similar to Response. Redirect (""), the current page jumps to a page. However, you can use the data submitted on the current page.


2. character encoding

.HTMLEncode (): displays html tags in text format.
.URLEncode (): use the same method to output special characters as plain text.

Sample Code:

// Do not use HTMLEncode to output protected void Button3_Click (object sender, EventArgs e) {Response. write ("

Result Display



3. Path Conversion

.MapPath (): returns the physical path of the execution file on the server through the relative path.


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.