WebRequestExecutor is the only modification point for ASP. net ajax network access infrastructure. Theoretically, we can use a custom WebRequestExecutor to replace the default XMLHttpExecutor. All we need to do is develop a class that inherits from Sys. Net. WebRequestExecutor. But in fact, in actual use, Sys. Net. XMLHttpExecutor is enough. To customize it, you only need to inherit this class. Just like the following example.
However, as a parent class, Sys. Net. XMLHttpExecutor is quite unfriendly. Let's get started. In this example, we will develop a TraceExecutor. If this Executor is used, the Request and Response information will be printed on the page. developers can take this content as a reference. TraceExecutor is very simple and the code is very short.
In general, all "private" variables are initialized in this method. But here we don't need it.
Then, we will overwrite the executeRequest method of XMLHttpExecutor. What we need to do is print the WebRequest object on the page. The Code is as follows:
- function Jeffz$Net$TraceExecutor$executeRequest()
- {
- debug.trace("<b>Request sent at " + new Date() + ":</b>");
- debug.dump(this.get_webRequest(), "Request");
- Jeffz.Net.TraceExecutor.callBaseMethod(this, "executeRequest");
- }
In Debug mode, I create an "alias" for the method, which needs to be used in prototype. Naturally, we also need to call registerClass to indicate the inheritance relationship of the class. The Code is as follows:
- Jeffz.Net.TraceExecutor.prototype =
- {
- executeRequest : Jeffz$Net$TraceExecutor$executeRequest
- }
- Jeffz.Net.TraceExecutor.registerClass('Jeffz.Net.TraceExecutor',
Sys.Net.XMLHttpExecutor);
We can try to use it. The code is very simple and HTML and Javascript are pasted together. The Code is as follows:
- <asp:ScriptManager runat="server" ID="ScriptManager1">
- <Scripts>
- <asp:ScriptReference Path="Debug.js" />
- <asp:ScriptReference Path="TraceExecutor.js" />
- </Scripts>
- </asp:ScriptManager>
- <asp:UpdatePanel runat="server" ID="UpdatePanel1">
- <Triggers>
- <asp:AsyncPostBackTrigger ControlID="btnRefresh" />
- </Triggers>
- <ContentTemplate>
- <%= DateTime.Now.ToString("r") %>
- </ContentTemplate>
- </asp:UpdatePanel>
- <asp:Button runat="server" ID="btnRefresh" Text="Refresh"/>
- <script language="javascript">
- Sys.Net.WebRequestManager.set_defaultExecutorType("Jeffz.Net.TraceExecutor");
- </script>
The preceding section describes WebRequestExecutor in ASP. NET.
- ASP. net mvc Web Application Project
- IIS6 ASP. net isapi request processing process
- Seven user management controls for ASP. NET controls
- RSA encryption for ASP. Net
- How to obtain database strings using ASP. NET