UriTemplate.BindByName Method (Uri, NameValueCollection)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Creates a new URI from the template and the collection of parameters.

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

Public Function BindByName (
	baseAddress As Uri,
	parameters As NameValueCollection
) As Uri

Parameters

baseAddress
Type: System.Uri

The base address.

parameters
Type: System.Collections.Specialized.NameValueCollection

The parameter values.

Return Value

Type: System.Uri

A new instance.

The NameValueCollection parameter contains a collection of parameter name/value pairs. The parameters are matched up against the variables within the template by a case-insensitive comparison. Values passed in this collection are escaped.

System_CAPS_noteNote

The name/value collection passed to BindByName(Uri, NameValueCollection) must contain a key for every template variable. Extra name/value pairs that do not match template variables are appended to the query string of the final URI.

System_CAPS_noteNote

It is possible to pass in text within the name/value pairs that prevent the generated URI from matching the template that is used to generate it. Examples of such text includes: '/', '..', '*', '{', and '}'.

The following example shows how to call the BindByName(Uri, NameValueCollection) method.

Dim template As UriTemplate = New UriTemplate("weather/{state}/{city}?forecast={day}")
Dim prefix As Uri = New Uri("http://localhost")

Dim parameters As NameValueCollection = New NameValueCollection()
parameters.Add("state", "Washington")
parameters.Add("city", "Redmond")
parameters.Add("day", "Today")
Dim namedUri As Uri = template.BindByName(prefix, parameters)

.NET Framework
Available since 3.5
Return to top
Show: