Поделиться через


WebRequest.CreatorInstance Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

When overridden in a descendant class, gets the factory object derived from the IWebRequestCreate class used to create the WebRequest instantiated for making the request to the specified URI.

Namespace:  System.Net
Assembly:  System.Net (in System.Net.dll)

Syntax

'Declaration
Public Overridable ReadOnly Property CreatorInstance As IWebRequestCreate
public virtual IWebRequestCreate CreatorInstance { get; }

Property Value

Type: System.Net.IWebRequestCreate
The derived WebRequest type returned by the Create method.

Remarks

This property allows an application to determine which IWebRequestCreate derived factory object was used to create the request. This object may be WebRequestCreator.BrowserHttp or WebRequestCreator.ClientHttp, but it may also be a custom instance derived from IWebRequestCreate. This allows an application to determine whether the browser hosting Silverlight, the Silverlight client, or some custom object handles HTTP requests and responses for the WebRequest instance. The RegisterPrefix method allows an application to configure which derived WebRequest type will be instantiated when making a request to a specific URI. WebRequest creators are typically registered to handle a specific protocol, such HTTP or HTTPS, but can be registered to handle a request to a specific server or path on a server. This is useful when more than one derived WebRequest type can process requests for the same protocol. The Silverlight 3 and later runtime supports multiple HTTP handlers each having different capabilities. For example, a web service that uses Representational State Transfer (REST) might require the WebRequestCreator.ClientHttp handler while a SOAP web service might be able to use the default WebRequestCreator.BrowserHttp handler.

Examples

' Change this Uri to an accessible server 
Dim uri As System.Uri = New Uri("https://www.contoso.com")

' Create a 'WebRequest' object.
Dim webRequest As WebRequest = WebRequest.Create(uri)

' Get the 'CreatorInstance' property and print the current value
outputBlock.Text &= "WebRequest.CreatorInstance: "
IF webRequest.CreatorInstance Is WebRequestCreator.BrowserHttp THEN
    outputBlock.Text &= "BrowserHttp"
    outputBlock.Text &= vbCrLf
ELSEIF webRequest.CreatorInstance Is WebRequestCreator.ClientHttp THEN
    outputBlock.Text &= "ClientHttp"
    outputBlock.Text &= vbCrLf
ELSE
    outputBlock.Text &= "Custom"
    outputBlock.Text &= vbCrLf
END IF
// Change this Uri to an accessible server
System.Uri uri = new Uri("https://www.contoso.com");

WebRequest webRequest = WebRequest.Create(uri);

outputBlock.Text += "WebRequest.CreatorInstance: ";
if (webRequest.CreatorInstance == WebRequestCreator.BrowserHttp)
{
    outputBlock.Text += "BrowserHttp";
    outputBlock.Text += "\n";
}
else if (webRequest.CreatorInstance == WebRequestCreator.ClientHttp)
{
    outputBlock.Text += "ClientHttp";
    outputBlock.Text += "\n";
}
else
{
    outputBlock.Text += "Custom";
    outputBlock.Text += "\n";
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.