Response object
In response to the client, the user sends a request refers to the server, the server either the processing result, the final result must be feedback to the user.
Response
Built-in member
Cookies
Properties: responseCookie
information, it is necessary to set a goodCookie
object is assigned to this propertyWrite
METHODS: Send page content to the pageRediect
Methods: page redirectsAddHeader
Methods: The end of the header information is added to the customerAppendToLog
Methods: Self-defined log information is added to theIIS
log file inside
Write
The method of data to the page output
Using the Write
method of outputting character data may be an array of characters, strings, objects, or other documents. For example, you want to export some verses on the page, create a new Web site, in the corresponding .aspx.cs
file Page_Load
method to write the following code:
protected void Page_Load(object sender, EventArgs e)
{
Response_Pt1(); //为了方便起见……写一个方法代替要输出的语句
}
private void Response_Pt1()
{
string[] arr = new string[5];
arr[0] = "天净沙·秋思";
arr[1] = "      ——马致远";
arr[2] = "枯藤老树昏鸦,小桥流水人家。";
arr[3] = "古道西风瘦马。";
arr[4] = "夕阳西下,断肠人在天涯。";
for (int i = 0; i < 5; i++)
{
Response.Write(arr[i] + "</br>");
}
}
Then click Run in the pop-up page you can see the verses. The code  
represents the output of a space.
If you want to verses word for word the pop-up effect output on the page, can be used with Response
the Flush
method and Thread
the Sleep
method of implementation in which Flush
the method refers to the sending of all the current output buffer to the client, Sleep
is the current process suspend the number of seconds, the following is the implementation code:
private void Response_Pt1()
{
string[] arr = new string[5];
arr[0] = "天净沙·秋思";
arr[1] = "    ——马致远";
arr[2] = "枯藤老树昏鸦,小桥流水人家。";
arr[3] = "古道西风瘦马。";
arr[4] = "夕阳西下,断肠人在天涯。";
for(int i = 0; i < arr.Length; i++)
{
foreach(char c in arr[i])
{
Response.Write(c);
Response.Flush(); //向客户端发送当前缓冲的输出
Thread.Sleep(100); //将当前进程挂起0.1秒
}
Response.Write("</br>");
}
}
Redirect
Page redirects
When users browse a Web site wants to jump to another page when this process is called redirection page, for example, will be redirected to the page welcome.aspx
when the page:
Response.Redirect("~/welcome.aspx");
If you want to this page transmission parameters, then .aspx
adding a back ?
, if a plurality of parameters among the plurality of parameters then add &
interval like, such as:
Response.Redirect("~/welcome.aspx?name=wzq&sex=man");
This is to welcome.aspx
page two passed parameters name
and sex
can be obtained through three different ways parameter values [Please point me ~] , the Request
objects inside it!
In this example, add a button in the first screen, if the button is clicked, passing name
and sex
parameter, jump to the welcome.aspx
page and the page output in "Welcome name sex
to visit!"
First, add a first interface button
control, and give him a response to the event, as follows:
protected void btnOK_Click(object sender, EventArgs e)
{
Response.Redirect("~/welcome.aspx?name=wzq&sex=先生");
}
Then the new welcome.aspx
page Page_Load
receiving method these two parameters, and outputs the contents on a page, as follows:
protected void Page_Load(object sender, EventArgs e)
{
string name = Request.Params["name"];
string sex = Request.Params["sex"];
Response.Write("欢迎" + name + sex + "!");
}
- Picture taken from the science and technology of tomorrow "zero-based learning asp.net", delete invasion