Sys.Net.WebRequestManager Class

Manages the flow of the Web requests issued by the Sys.Net.WebRequest object to the associated executor object.

Namespace: Sys.Net

Inherits: None




Sys.Net.WebRequestManager Constructor

Initializes a new instance of the Sys.Net.WebRequestManager class when implemented in a derived class.

Sys.Net.WebRequestManager add_completedRequest Method

Registers a handler for the completed request event of the WebRequestManager.

Sys.Net.WebRequestManager add_invokingRequest Method

Registers a handler for the invoking request event of the WebRequestManager.

Sys.Net.WebRequestManager remove_completedRequest Method

Removes the event handler set by the add_completedRequest method.

Sys.Net.WebRequestManager remove_invokingRequest Method

Removes the event handler set by the add_invokingRequest method.

Sys.Net.WebRequestManager.executeRequest Method

Executes the specified Web request.

Sys.Net.WebRequestManager defaultExecutor Property

Gets or sets the default executor for the Web request.

Sys.Net.WebRequestManager defaultTimeout Property

Gets or sets the default time-out for the Web request.

Sys.Net.WebRequestManager completedRequest Event

Occurs when a request has been handled.

Sys.Net.WebRequestManager invokingRequest Event

Occurs when a handler function is called for the request.

The default executor associated with a WebRequest object is an instance of the XmlHttpExecutor class. The executor is responsible for making the actual network requests.

The WebRequestManager class defines the default behavior for all Web requests so that you do not have to specify low-level network configuration settings for each request.

Each page contains only one WebRequestManager instance. However, you might have several instances of the WebRequest class and related executor.

The following example shows how to use the WebRequestManager class to set common properties and to execute a Web request. The example shows a Web page and the client script used to interact with the WebRequestManager class.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
    <head id="Head1" runat="server">

        <title> WebRequestManager  Example </title>

        <style type="text/css">
            body {  font: 11pt Trebuchet MS;
                    font-color: #000000;
                    padding-top: 72px;
                    text-align: center }

            .text { font: 8pt Trebuchet MS }



    <h2>WebRequestManager Example</h2>

        <form id="form1" runat="server">
            <asp:ScriptManager runat="server" ID="scriptManagerId">
                    <asp:ScriptReference Path="WebRequestManager.js" />

            <tr align="left">
                <td>Make a Web request:</td>
                    <button id="Button1" 
                        title="adds and remove handlers, too"  
                        onclick="MakeWebRequest(); return false;">Web Request</button>

            <tr align="left">
                <td>Set, get default executor:</td>
                    <button id="Button2"  
                        onclick="DefaultExecutor(); return false;">Executor</button>

           <tr align="left">
                <td>Set, get default timeout:</td>
                    <button id="Button3" 
                        onclick="DefaultTimeout(); return false;">Timeout</button>


        <hr />

        <div id="ResultId" style="background-color:Aqua;"></div>


var displayElement;

function pageLoad()
    displayElement = $get("ResultId");

// Adds invokingRequest and completedRequest
// handlers, and performs a Web request. 
function MakeWebRequest() 
    // Clear the previous results. 
    resultElement.innerHTML = "";

    // Instantiate a Web request.
    wRequest =  new Sys.Net.WebRequest();

    // Set the handler to process the Web request.

    alert("Added On_WebRequestCompleted handler.");

    // Set the handler to call before the Web request
    // is executed.

    alert("Added On_InvokingRequest handler.");

    // Set the request Url.  

    // Execute the request.
    // Notice that you do not use the executeRequest method of
    // the WebRequestManager which is intended for internal 
    // use only as in: Sys.Net.WebRequestManager.executeRequest(wRequest).
    // The correct way to execute a request is the following:
    // wRequest.invoke();


// Removes the event handlers that were previusly added. 
function RemoveDefaultHandlers() 
    // Clear the previous results. 
    resultElement.innerHTML = "";


    alert("Removed On_WebRequestCompleted handler.");


    alert("Removed On_InvokingRequest handler.");


// Gets and sets the default executor.
function DefaultExecutor()
    // Clear the previous results. 
    resultElement.innerHTML = "";

    // Get system default executor type.
    var sysDefaultExecutor = 
    alert("Get default executor:" + sysDefaultExecutor);

    // Modify the default executor type.

    var customDefaultExecutor = 

    alert("Set default executor: " + customDefaultExecutor);

    // Set the executor back to the system default. This is 
    // to allow the WebRequest script to run.
    executor = "Sys.Net.XMLHttpExecutor";


// Gets and sets the default timeout.
function DefaultTimeout()
    // Clear the previous results. 
    resultElement.innerHTML = "";

    // Get system default timeout.
    var sysDefaultTimeout = 

    alert("Get default timeout: " + sysDefaultTimeout);

    // Set custom default timeout.

    var customDefaultTimeout = 

    alert("Set default timeout: " + customDefaultTimeout);

    // Set the timeout back to the system default. 


// The On_InvokingRequest can be used to perform
// processing prior to the Web request being executed. 
function On_InvokingRequest(executor, eventArgs)
    alert("Executing OnInvokingRequest handler, before the Web request.");

    // Add custom code to perform processing prior
    // to the request being executed or to abort the 
    // request.
    alert("The current executor is: " + 

    // Use the eventArgs of type
    // NetworkRequestEventArgs to access the 
    // current WebRequest instance.
    var currentRequest = eventArgs.get_webRequest();
    var requestUrl = currentRequest.getResolvedUrl();           
    alert("Current request URL: " + requestUrl);

// The On_WebRequestComplete occurs after the
// Web request has returned, and can be used to
// get error status, process returned data, etc...
function On_WebRequestCompleted(executor, eventArgs) 


        // Clear the previous results. 
        resultElement.innerHTML = "";

        // Display Web request status.                 
        resultElement.innerHTML  +=
          "Status: [" + executor.get_statusCode() + " " + 
                    executor.get_statusText() + "]" + "<br/>";

        // Display Web request headers.
        resultElement.innerHTML  += 
            "Headers: ";
        resultElement.innerHTML  += 
            executor.getAllResponseHeaders() + "<br/>";

        // Display Web request body.
        resultElement.innerHTML += 
            "Body: ";

        resultElement.innerHTML  +=