We talked about Request in the last class, and next we must talk about his wife Response. Last time, we said that Request is mainly to get information. So this time we have to talk about the output data of Response. Of course, she can not only output data. , she will also redirect the page and add customized log records.
Don’t worry, the concept is boring. But it still has to be said, and I will try to make it less interesting.
First of all, we need to know that Response comes from the HTTPResponse class. It is mainly used to respond to the client, telling the browser the header of the response content, the server-side information and the output specified content.
ContentType, a string that mainly describes the content type. The format of this string is type/subtype. The former represents content classification, and the latter represents a specific content type. It can set or get the data type. The default value is text/html.
For example, Response.ContentType = "image/gif"; means outputting an image in gif format
Response.Clear();
This method is used to delete all HTML output stored in the buffer, but it only deletes those that are prepared for output, and does not delete Response header information.
Response.ClearHeaders(): This only deletes header information.
Response.ClearContent(): This deletes all
Responses. .Expires=5;: Get or set the page expiration time. For example, in this sentence we set 5 minutes. Then within 5 minutes of opening the page, when you visit the page, it will only display the data in the cache, and it will restart after 5 minutes. Go to the server to download. The unit of this setting time is minutes.
Response.ExpiresAbsolute = DateTime.Now.AddHours(8);: This is originally for compatibility with asp. It sets the absolute time for cache removal. For example, in this sentence, we set the removal time to the current time plus 8 hours, that is It expires after 8 hours. What follows is a time format. If not specified, the cache overflows at midnight.
Response.Buffer = false;: Set or get whether the current page buffers output, the value is bool, the default is true
Response.Flush();: Immediately output the buffered output to
Response.End();: Immediately output the current buffer content, And stop the execution of the current page.
As for displaying data, this is nothing new to us. In fact, redirection is also very simple. Let’s look at one below.
Server object:
We don’t often use this.
Let me show you an example.