Share via


WwwFormUrlDecoder.GetFirstValueByName(String) Method

Definition

Gets the first name-value pair that has the specified name, as obtained from the constructing Uniform Resource Identifier (URI) query string.

public:
 virtual Platform::String ^ GetFirstValueByName(Platform::String ^ name) = GetFirstValueByName;
winrt::hstring GetFirstValueByName(winrt::hstring const& name);
public string GetFirstValueByName(string name);
function getFirstValueByName(name)
Public Function GetFirstValueByName (name As String) As String

Parameters

name
String

Platform::String

winrt::hstring

The name of the value to get.

Returns

String

Platform::String

winrt::hstring

The first value in list order that corresponds with name.

Remarks

This method throws an exception (an error for JavaScript) if the value specified as name doesn't exist in the WwwFormUrlDecoder collection. For .NET code, this is typed as System.ArgumentException. You'll probably want to call GetFirstValueByName within a try-catch block so you have a chance to handle the exception.

What to do with duplicate names in a query string from a GET request is not specified by any Internet standard. A common practice is to process the first value and ignore the subsequent duplicates. The GetFirstValueByName method provides that behavior. It also provides the de-facto "index by string" behavior, which is typically what you want when you're processing a query string. Your app is expecting certain names to be present on the query string, and wants to retrieve the associated value.

Applies to