WebRequestExecutor in ASP. NET

Source: Internet
Author: User

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:

 
 
  1. function Jeffz$Net$TraceExecutor$executeRequest()  
  2. {  
  3. debug.trace("<b>Request sent at " + new Date() + ":</b>");  
  4. debug.dump(this.get_webRequest(), "Request");  
  5. 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:

 
 
  1. Jeffz.Net.TraceExecutor.prototype =  
  2. {  
  3. executeRequest : Jeffz$Net$TraceExecutor$executeRequest  
  4. }  
  5. 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:

 
 
  1. <asp:ScriptManager runat="server" ID="ScriptManager1"> 
  2. <Scripts> 
  3. <asp:ScriptReference Path="Debug.js" /> 
  4. <asp:ScriptReference Path="TraceExecutor.js" /> 
  5. </Scripts> 
  6. </asp:ScriptManager> 
  7. <asp:UpdatePanel runat="server" ID="UpdatePanel1"> 
  8. <Triggers> 
  9. <asp:AsyncPostBackTrigger ControlID="btnRefresh" /> 
  10. </Triggers> 
  11. <ContentTemplate> 
  12. <%= DateTime.Now.ToString("r") %> 
  13. </ContentTemplate> 
  14. </asp:UpdatePanel> 
  15. <asp:Button runat="server" ID="btnRefresh" Text="Refresh"/> 
  16. <script language="javascript"> 
  17. Sys.Net.WebRequestManager.set_defaultExecutorType("Jeffz.Net.TraceExecutor");  
  18. </script>  

The preceding section describes WebRequestExecutor in ASP. NET.

  1. ASP. net mvc Web Application Project
  2. IIS6 ASP. net isapi request processing process
  3. Seven user management controls for ASP. NET controls
  4. RSA encryption for ASP. Net
  5. How to obtain database strings using ASP. NET

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.