6 large built-in objects for ASP Web development

Source: Internet
Author: User

6 large built-in objects for ASP Web development

ASP. NET built-in objects include 1.Response 2.Request 3.Server 4.Application 5.Session 6.Cookie

1 The Request object is primarily for the server to get some data from the client browser, including parameters, cookies, and user authentication that are passed from the HTML table with the post or get method alone.

2 The Request object is one of the members of the Page object.

The

3 program does not require any declaration to be used directly; its class name is HttpRequest property, but there are few methods, only one BinaryRead ()
1. Get Data using Request.Form property
  Through this property, Reads the form data between. Note: The submission method should be set to "Post". Compared to the Get method, a post method can be used to send large amounts of data to server-side
2. Use the Request.QueryString property to get the data
  Request object's Querysting property to get the HTTP A collection of query string variables. With this property, we can read the address information   HTTP://LOCALHOST/AAA.ASPX?UID=TOM&PWD=ABC the data that is identified in the Red section. Note: The submission method is set to "Get"
3. Problem: Request.Form is used when the form is submitted as a post, and request.querystring is used when the form is submitted as get, and if it is used incorrectly, the data is not available. Workaround: Use the request ("element name") to simplify the operation.

     1.response.write variable data or string     Response.Write (variable data or string)

< %=...%>response.write ("alert (' Welcome to Learning ASP)")  

Response.Write ("")  

2. The redirect method of the Response object redirects the client browser to a different URL, which jumps to another Web page. For example: Response.Redirect ("http://www.example.com/")

3. Response.End () Terminates the current page's run

4.response.writefile (filename) Where: filename refers to the file name of the files that need to be output to the browser


The server object provides access to the methods and properties on the server. Its class name is HttpServerUtility.
The main properties of the server object are

MachineName: Gets the computer name of the server.
ScriptTimeout: Gets and sets the request time-out (in seconds).
Method Name Description

CreateObject creates a server instance of a COM object.

Execute executes another ASPX page on the current server, executes the page, and then returns to this page for execution

HtmlEncode HTML-encodes the string to be displayed in the browser and returns the encoded string.

HtmlDecode decodes the HTML-encoded string and returns the decoded string.

MapPath returns the physical file path corresponding to the specified virtual path on the WEB server.

Transfer terminates execution of the current page and begins execution of a new page for the current request.

UrlEncode encodes a string representing the URL so that it can be reliably transmitted from the WEB server to the client via a URL.

UrlDecode decodes a URL string that has been encoded and returns the decoded string.

Urlpathencode URL-encodes the path portion of the URL string and returns the encoded string.

Code: Server.HTMLEncode ("HTML code")

Decoding: Server.htmldecode ("encoded HTML")

The MapPath method of the 1.Server object converts the virtual path or relative path relative to the current page to the physical file path on the Web server. Grammar:

Server.MapPath ("virtual path")
String FilePath
FilePath = Server.MapPath ("/")
Response.Write (FilePath)



The purpose of the Application object in the actual network development is to record the information of the whole network, such as the number of people on the line, the online list, the opinion survey and the online election. Share information among many users of a given application and persist data for the duration of the server run. The Application object also has a way to control access to application-tier data and events that can be used to trigger the process when the application starts and stops.

1. Use Application object to save information application ("key name") = value or application ("Key Name", value) to get Application object information Variable name = Application ("Key Name") OR: Variable name = Application.item ("Key Name") OR: Variable name = Application.get ("Key name") updates the value of the Application object

Application.set ("Key Name", value)

Delete a key

Application.remove ("Key Name", value)

Remove all keys

Application.removeall () or application.clear ()
2. There may be situations where multiple users can access the same Application object at the same time. This makes it possible for multiple users to modify the same application named object, resulting in inconsistent data issues. The HttpApplicationState class provides two methods of Lock and Unlock to resolve access synchronization issues with application objects, allowing only one thread to access application state variables at a time.

About locking and unlocking

Lock: Application.Lock ()

Access: Application ("key name") = value

Unlock: Application.UnLock ()

Note: The lock method and the Unlock method should be used in pairs. Can be used for website visitors, chat rooms and other equipment.
3. Using the Application event

In an ASP. NET application, you can include a special optional file,--global.asax file, also known as an ASP. NET application file, which contains a response to ASP. NET or HTTP module raises the code for an application-level event. The Global.asax file provides 7 events, 5 of which are applied to the Application object

Event name Description

Application_Start fires when the application starts

Application_BeginRequest fires at the beginning of each request

Application_AuthenticateRequest fires when attempting to authenticate a consumer

Application_Error fires when an error occurs

Application_End fires at end of application

A

Session is a conversation that refers to a user's access to a site for a period of time.   The

Session object corresponds to the HttpSessionState class in. NET, which represents "session state" and can hold information related to the current user session. The
Session object is used to store the information that is required for a particular user session, starting from a user's access to a particular ASPX page, to the user's departure. The variables of the session object are not cleared when the user switches the application's page. For a Web application, the content of the Application object accessed by all users is exactly the same, while the content of the session object accessed by different user sessions varies. Session can save the variable, which can only be used by one user, that is, each Web browser has its own session object variable, that is, the session object is unique.
(1) Add new item to session state

Syntax format:

Session ("key name") = value

or

Session.add ("Key Name", value)

(2) by name The value in the get session state is called the

Syntax format:

variable = session ("Key Name")  

or

variable = session.item ("Key Name")

(3) Delete  The entry in the Conversation state collection is in the

Syntax format: session.remove ("Key Name")

(4) Clears all values in the session state

Syntax format: session.removeall ()

or Session.clear ()

(5) cancels the current session

Syntax format: Session.Abandon ()

(6) Sets the session state time-out period, in minutes. The

Syntax format is: session.timeout = value

The Global.asax file has 2 events applied to the Session object  

Event name Description

Session_sta RT fires

When the session is started session_end fires at the end of the session

A cookie is a piece of text that a Web server saves on a user's hard disk. A cookie allows a Web site to save information on a user's computer and then retrieve it later. Pieces of information are stored in the form of ' key/value ' pairs.

A cookie is a text file stored on a client's hard disk that stores information about a specific client, session, or application, and corresponds to the HttpCookie class in. Net. There are two types of cookies: Session cookies and persistent cookies. The former is temporary, and once the session state ends it will no longer exist; the latter has a definite expiration date, and the cookie is stored as a text file on the user's computer before it expires. Creating and outputting cookies to the client on the server can take advantage of the response object implementation.

6 large built-in objects for ASP Web development

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.