Registers a System.Net.WebRequest descendant for the specified URI.
- prefix
The complete URI or URI prefix that the System.Net.WebRequest descendant services.
- creator
The create method that the System.Net.WebRequest calls to create the System.Net.WebRequest descendant.
![]()
true if registration is successful; otherwise, false.
Type Reason ArgumentNullException prefix is null or creator is null.
The WebRequest.RegisterPrefix(string, IWebRequestCreate) method registers System.Net.WebRequest descendants to service requests. System.Net.WebRequest descendants 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.
The pre-registered reserve types already registered include the following:
http://
https://
ftp://
file://
For more information, see the WebRequest.Create(string) and WebRequest.Create(Uri) methods.
Duplicate prefixes are not allowed. WebRequest.RegisterPrefix(string, IWebRequestCreate) returns false if an attempt is made to register a duplicate prefix.
The System.Net.HttpWebRequest class is registered to service requests for HTTP and HTTPS schemes by default. Attempts to register a different System.Net.WebRequest descendant for these schemes will fail.
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