ReverseAjax invert AJAX is a Web Implementation Mode Designed to transfer logical control to the server.
What is Control Transfer
Traditional AJAX calls are generally triggered by client behavior, such as regional data acquisition and asynchronous verification.
ReverseAjax transfers control to the server, just as the server triggers client events, that is, a very early Web push technology.
ASP. NET requires the asynchronous page technology to implement a variable-length connection, and the session must be disabled for the page to generate a new instance for each request.
Copy codeThe Code is as follows: <% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "response. aspx. cs "Inherits =" _ Default "Async =" true "AsyncTimeout =" 30 "EnableSessionState =" False "%>
If (Request. Form. Count> 0)
{
If (Request. Form ["type"] = "loop ")
{
ChatTask task = new ChatTask (this. Context );
Task. _ chatNow = this. ChatNow; // There is a callback method for the new message, that is, notification processing. At this time, the connection is released.
String user = Request. Form ["user"]. Trim ();
PageAsyncTask async = new PageAsyncTask (new BeginEventHandler (task. OnBegin), new EndEventHandler (task. OnEnd), new EndEventHandler (task. OnTimeout), user );
Page. RegisterAsyncTask (async );
Page. ExecuteRegisteredAsyncTasks (); // asynchronous execution
}
}
For specific code and implementation effects, see examples.
Attachment:
Example program: reverseajaxchat .rar