建立一份新的aspx页面,在aspx.cs里的page_load里加上如下代码...然后保存,访问一下...就可以看到服务器推送模式的效果了...
protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "multipart/x-mixed-replace;boundary=--TempString--";
HttpContext.Current.Response.StatusCode = 200;
HttpContext.Current.Response.Write("");
HttpContext.Current.Response.Write("--TempString--\r\n");
HttpContext.Current.Response.Flush();
while (HttpContext.Current.Response.IsClientConnected)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write("date : " + DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss") + "\r\n");
HttpContext.Current.Response.Write("--TempString--\r\n");
HttpContext.Current.Response.Flush();
Thread.Sleep(1000);
}
}
转载于:https://www.cnblogs.com/greywolf/archive/2012/12/18/2822777.html