Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// <Snippet1>

using System;
using System.Web;

class Program
{
static void Main()
{
// Parse the URL and get the query string
var url = "https://www.microsoft.com?name=John&age=30&location=USA";
var parsedUrl = url.Split('?')[1];

// The ParseQueryString method will parse the query string and return a NameValueCollection
var paramsCollection = HttpUtility.ParseQueryString(parsedUrl);

// The foreach loop will iterate over the params collection and print the key and value for each param
foreach (var key in paramsCollection.AllKeys)
{
Console.WriteLine($"Key: {key} => Value: {paramsCollection[key]}");
}
}
}

// The example displays the following output:
// Key: name => Value: John
// Key: age => Value: 30
// Key: location => Value: USA

// </Snippet1>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
' <Snippet1>

Imports System.Collections.Specialized
Imports System.Web

Public Class Sample
Public Shared Sub Main()
' Parse the URL and get the query string
Dim url As String = "https://www.microsoft.com?name=John&age=30&location=USA"
Dim parsedUrl As String = url.Split("?")(1)

' The ParseQueryString method will parse the query string and return a NameValueCollection
Dim paramsCollection As NameValueCollection = HttpUtility.ParseQueryString(parsedUrl)

' The For Each loop will iterate over the params collection and print the key and value for each param
For Each key As String In paramsCollection.AllKeys
Console.WriteLine($"Key: {key} => Value: {paramsCollection(key)}")
Next
End Sub
End Class

' The example displays the following output:
' Key: name => Value: John
' Key: age => Value: 30
' Key: location => Value: USA

' </Snippet1>
8 changes: 4 additions & 4 deletions xml/System.Web/HttpUtility.xml
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@
<format type="text/markdown"><![CDATA[

## Remarks
The <xref:System.Web.HttpUtility.ParseQueryString%2A> method uses <xref:System.Text.Encoding.UTF8%2A> format to parse the query string In the returned <xref:System.Collections.Specialized.NameValueCollection>, URL-encoded characters are decoded and multiple occurrences of the same query string parameter are listed as a single entry with a comma separating each value.
The <xref:System.Web.HttpUtility.ParseQueryString%2A> method uses <xref:System.Text.Encoding.UTF8%2A> format to parse the query string In the returned <xref:System.Collections.Specialized.NameValueCollection>, URL encoded characters are decoded and multiple occurrences of the same query string parameter are listed as a single entry with a comma separating each value.

> [!IMPORTANT]
> The <xref:System.Web.HttpUtility.ParseQueryString%2A> method uses query strings that might contain user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see [Script Exploits Overview](https://docs.microsoft.com/previous-versions/aspnet/w1sw53ds(v=vs.100)).
Expand All @@ -857,8 +857,8 @@
## Examples
The following code example demonstrates how to use the <xref:System.Web.HttpUtility.ParseQueryString%2A> method. Multiple occurrences of the same query string variable are consolidated in one entry of the returned <xref:System.Collections.Specialized.NameValueCollection>.

:::code language="aspx-csharp" source="~/snippets/csharp/VS_Snippets_WebNet/HttpUtility_ParseQueryString/cs/httputility_parsequerystring.aspx" id="Snippet1":::
:::code language="aspx-vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/HttpUtility_ParseQueryString/vb/httputility_parsequerystring.aspx" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_WebNet/HttpUtility_ParseQueryString/cs/httputility_parsequerystring.cs" interactive="try-dotnet" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/HttpUtility_ParseQueryString/vb/httputility_parsequerystring.vb" id="Snippet1":::

]]></format>
</remarks>
Expand Down Expand Up @@ -922,7 +922,7 @@
<format type="text/markdown"><![CDATA[

## Remarks
In the returned <xref:System.Collections.Specialized.NameValueCollection>, URL-encoded characters are decoded and multiple occurrences of the same query string parameter are listed as a single entry with a comma separating each value.
In the returned <xref:System.Collections.Specialized.NameValueCollection>, URL encoded characters are decoded and multiple occurrences of the same query string parameter are listed as a single entry with a comma separating each value.

> [!IMPORTANT]
> The <xref:System.Web.HttpUtility.ParseQueryString%2A> method uses query strings that might contain user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see [Script Exploits Overview](https://docs.microsoft.com/previous-versions/aspnet/w1sw53ds(v=vs.100)).
Expand Down