Lire en anglais Modifier

Partager via


UriTemplateMatch.QueryParameters Property

Definition

Gets a collection of query string parameters and their values.

C#
public System.Collections.Specialized.NameValueCollection QueryParameters { get; }

Property Value

A NameValueCollection instance that contains the query string parameters and their values.

Examples

The following code shows how to access the QueryParameters property.

C#
UriTemplate template = new UriTemplate("weather/{state}/{city}?forecast=today");
Uri baseAddress = new Uri("http://localhost");
Uri fullUri = new Uri("http://localhost/weather/WA/Seattle?forecast=today");

Console.WriteLine("Matching {0} to {1}", template.ToString(), fullUri.ToString());

// Match a URI to a template
UriTemplateMatch results = template.Match(baseAddress, fullUri);
if (results != null)
{
    Console.WriteLine("QueryParameters:");
    foreach (string queryName in results.QueryParameters.Keys)
    {
        Console.WriteLine("    {0} : {1}", queryName, results.QueryParameters[queryName]);
    }
    Console.WriteLine();
}
// Code output:
//  QueryParameters:
//  forecast : today

Remarks

All query string name/value pairs from the original URI appear in this collection, even if they are not explicitly specified in the template string that was matched. The values in this collection have been had all escape sequences translated into actual characters.

Applies to

Produit Versions
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1