Response Object
The Respose object is used to send data back to the browser from the server. It allows the data to be sent as the result of the request to the browser, and provides light-responsive information that can be used to enter data in the page, jump in the page, and pass the parameters of each page, which corresponds to the corresponding message in the HTTP protocol.
Response Object Common Properties
Property |
|
Buffer |
Gets or sets a value that indicates whether the output is buffered and sent after the entire response has been processed |
Cache |
Gets the Web page's cache policy, such as expiration time, privacy .... |
Charset |
Sets or gets the output string encoding of HTTP |
Expires |
Gets or sets the number of minutes before the page that is cached on the browser expires |
Cookies |
Gets the collection of cookies for the current request |
IsClientConnected |
Returns whether the client is still connected to the server |
Suppresscontent |
Sets whether to send HTTP content to the client browser, if true, the Web page will not be passed to the client |
Common methods for response objects
Method |
|
AddHeader |
Add an HTTP header to the output stream |
AppendToLog |
To add custom log information to an IIS log file |
Clear |
Clears the contents of the buffer |
End |
Sends all content in the current buffer to the client post-relationship |
Flush |
Sends all data in the buffer to the client |
Redirect |
To re-orient a webpage to another address |
Write |
outputting data to the client |
WriteFile |
Writes the specified file to the HTTP content output stream |
1. Output data in the page
The Response object outputs data on the page through the Write method or the WriteFile method. The output object can be a character, an array of characters, a string, an object, or a file.
Experiment a simple case, create an empty Web site, in the root directory to create a TextFile.txt file, the file content is "Hello,response ...". The procedure is as follows:
The run results are as follows,
Note that when the file is output, the file must already exist, and if it does not, it will produce a "file not found" exception.
2. Page jumps and passes parameters
You can implement page redirection through the redirect method of the Response object, and you can pass parameters when redirecting to a new URL.
The code that redirects the page to the Welcome.aspx page can be written like this:
This. Response.Redirect ("~/welcome.aspx");
Pass parameters when the page redirects the URL, using "?" Separate the page connection address and parameters, when there are multiple parameters, the parameters and parameters to use "&" separated.
Make a simple example experiment, add a Default.aspx page in the project just now, the page is simple to spend, the following:
To draw a simple page, run the following effect:
OK, the thing we're going to do now is to click OK and let it jump to the welcome.aspx page, so the simple implementation code for the Click event of the button is as follows:
The next thing to do is to create a new welcome.aspx page to accept the data, and then read the data and we'll be finished. The code for the new Welcome.aspx output information is as follows:
In fact, we have simply implemented the process, now run to see the effect, the effect is as follows:
OK, about response first simple to understand so much, just now we in the welcome.aspx to get the parameters of the connection with a reauest, which is also one of the ASP, we follow in to understand these things!
Hope the foundation of the article can be a new beginning to learn from the friends of the net help, everyone together to learn progress ....
"Recommended"
1. SPRINGMVC implements JSON interaction-requestbody and responsebody (graphic)
2. Angularjs's NG Http request and Response format conversion method
3. Java parsing XML in response
4. Summary of ASP. NET built-in objects (Response) Use method instances