[C #] [] asp.net built-in object Response object

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.


ResponseBuilt-in member
  • CookiesProperties: response Cookieinformation, it is necessary to set a good Cookieobject is assigned to this property
  • WriteMETHODS: Send page content to the page
  • RediectMethods: page redirects
  • AddHeaderMethods: The end of the header information is added to the customer
  • AppendToLogMethods: Self-defined log information is added to the IISlog file inside

WriteThe method of data to the page output

Using the Writemethod 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.csfile Page_Loadmethod 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] = "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp——马致远";
    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 &nbsprepresents 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 Responsethe Flushmethod and Threadthe Sleepmethod of implementation in which Flushthe method refers to the sending of all the current output buffer to the client, Sleepis 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] = "&nbsp&nbsp&nbsp&nbsp——马致远";
    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>");
    }
}

RedirectPage 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.aspxwhen the page:

Response.Redirect("~/welcome.aspx");

If you want to this page transmission parameters, then .aspxadding 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.aspxpage two passed parameters nameand sexcan be obtained through three different ways parameter values [Please point me ~] , the Requestobjects inside it!

In this example, add a button in the first screen, if the button is clicked, passing nameand sexparameter, jump to the welcome.aspxpage and the page output in "Welcome name sexto visit!"

First, add a first interface buttoncontrol, 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.aspxpage Page_Loadreceiving 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

Published 177 original articles · won praise 282 · views 30000 +

Guess you like

Origin blog.csdn.net/lesileqin/article/details/103437747