Introduction to the
Asp.net’s built-in objects make it easier to send messages.
The body of the
-
The Response object
Overview: Inherited from system.web. HttpRespone class, used to send information to the client, and control the sending process. For example, dynamically create Web page display content in the browser, change the HTTP header, redirect the client to the specified page, set buffer information, and so on.
Basic syntax: the Response properties | methods [.] [variable]; You can select only one of the two parameters: property and method. Variables are string variables that are used as arguments to methods.
Related attributes:
Example:
<body>
<! -- Add a button to the front -->
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Winni's blog" OnClick="Button1_Click" />
</div>
</form>
</body>
Copy the code
//.cs adds code to send a message to the browser and redirect it to open another web page. System.web.ui.Page {protected void Page_Load(object sender, EventArgs e) {response.write (" Present time is: "+ datetime.now); } protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("https://blog.csdn.net/hdy14/article/details/86658127"); }}Copy the code
Operation effect:
In this example, Response is used to pass a message to the browser: the current time. And the redirect opens a new page.
-
Request
The function of the Request object is to get data from the client, which I feel is the opposite of the Response object.
The attributes of the Request object are as follows:
Example:
Get the values entered by the browser, text box data, and assign them to the database (or entity).
-
Server
Server objects provide methods and properties for access to the Server, most of which are provided as utility functions. Common attributes of Server objects are as follows:
Example:
Get the Path to the current file using the Map Path method of the Server object. And use Response to output:
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("The time is:" + DateTime.Now);
Response.Write("The physical path of the current file is"+Server.MapPath("."));
}
Copy the code
Operation effect:
-
The Application object,
The Application object provides access to application-wide methods and events for all sessions and also provides access to application-wide caches that can be used to store information. Application state is a repository of data available to all classes in an ASP.NET application. It is stored in the server’s memory, so it performs faster than storing and retrieving information in a database. Unlike session state for specific and individual user sessions, application state applies to all users and sessions. Therefore, application state is ideal for storing frequently used data that is small in quantity and doesn’t change with the user.
Key features are:
It is stored in server memory, user-independent that is, shared by multiple users, and exists for the lifetime of the application without being actively discarded, serialized, or transferred between the server and the client.
The format is as follows:
Appliacation[” variable “]= “variable content”;
The attributes are as follows:
The events are as follows:
Example:
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
Copy the code
Application.Lock();
Application["usercount"] = (Convert.ToInt32(Application["usercount"]) + 1).ToString();
Application.UnLock();
Label1.Text = "You are the first." + Application["usercount"].ToString() + "A visitor.";
Copy the code
Operation effect:
-
The Session object
The Session object is used to store information about a particular user between multiple page calls. The Session object is for a single web user, and different clients cannot access each other. Session object termination The Session object variable is closed when the machine is offline, that is, when the web user closes the browser or exceeds the duration of the Session object.
The Session object is associated with a specific user. So sessions are single-user operations. Session objects are completely independent and do not affect each other. In other words, a user corresponds to a Session object, and each user has his or her own ID. The user information stored in the Session object is invisible to other users.
-
Cookie object
Users store user-specific information on the Web. Cookie attributes are as follows:
Application, Session, and Cookie objects
The Application object is shared by the entire Application, that is, multiple users share an Application object;
The Session object is exclusively owned by each user, and each user has a unique Session id. Users often store user information.
Cookie object Users protect client browser requests for information.
Application and Session save information to the server, while Cookie save information to the client.
Afterword.
ASP.NET built-in objects: JavaScript+Jquery