Mono Class Library: System.Net.WebRequest Overview | Members

System.Net.WebRequest.RegisterPrefix Method

Registers a type derived from System.Net.WebRequest, and associates the type with the specified URI. [Edit]

public static bool RegisterPrefix (string prefix, IWebRequestCreate creator)

Parameters

prefix
A string containing the URI that the derived type services. Can specify a scheme or a complete URI. [Edit]
creator
An instance of a type that implements the System.Net.IWebRequestCreate interface. [Edit]

Returns

true if registration is successful; false, if prefix is already registered. [Edit]

Exceptions

TypeReason
ArgumentNullExceptionprefix is null or creator is null. [Edit]

Remarks

System.Net.HttpWebRequest is registered to service requests for HTTP and HTTPS schemes. Attempts to register a different type for these schemes will fail.

Note:

This method registers types that derive from System.Net.WebRequest to service requests. These derived types are typically registered to handle a specific protocol, such HTTP or FTP, but can be registered to handle a request to a specific server or path on a server. Therefore, prefix can be either a scheme or a complete URI.

The System.Net.WebRequest class calls the IWebRequestCreate.Create(Uri) method to create additional instances of the same type as creator.

[Edit]

Example

The following example demonstrates how to register a new scheme.

C# Example
using System;
using System.Net;

public class ftpWebRequest : WebRequest {
   //implement ftp-specific protocol methods and properties
}

public class ftpCreator : IWebRequestCreate 
{
   public WebRequest Create(Uri uri) 
   {
      return new ftpWebRequest(); 
   }
}

public class RegisterPrefixExample
{

   public static void Main() 
   {
 
      ftpCreator creator = new ftpCreator();
      WebRequest.RegisterPrefix("ftp://", creator);
      WebRequest wr = WebRequest.Create("ftp://testFile");
      Console.WriteLine(wr);
   }
}
   

The output is

ftpWebRequest

Requirements

Namespace: System.Net
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0