diff --git a/snippets/csharp/VS_Snippets_WebNet/HttpUtility_ParseQueryString/cs/httputility_parsequerystring.aspx b/snippets/csharp/VS_Snippets_WebNet/HttpUtility_ParseQueryString/cs/httputility_parsequerystring.aspx deleted file mode 100644 index 6556b54acdc..00000000000 --- a/snippets/csharp/VS_Snippets_WebNet/HttpUtility_ParseQueryString/cs/httputility_parsequerystring.aspx +++ /dev/null @@ -1,56 +0,0 @@ - -<%@ Page Language="C#"%> - - - - - - - HttpUtility ParseQueryString Example - - -
- Query string variables are: - - - - - diff --git a/snippets/csharp/VS_Snippets_WebNet/HttpUtility_ParseQueryString/cs/httputility_parsequerystring.cs b/snippets/csharp/VS_Snippets_WebNet/HttpUtility_ParseQueryString/cs/httputility_parsequerystring.cs new file mode 100644 index 00000000000..8c928a161a4 --- /dev/null +++ b/snippets/csharp/VS_Snippets_WebNet/HttpUtility_ParseQueryString/cs/httputility_parsequerystring.cs @@ -0,0 +1,30 @@ +// + +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 + +// \ No newline at end of file diff --git a/snippets/visualbasic/VS_Snippets_WebNet/HttpUtility_ParseQueryString/vb/httputility_parsequerystring.aspx b/snippets/visualbasic/VS_Snippets_WebNet/HttpUtility_ParseQueryString/vb/httputility_parsequerystring.aspx deleted file mode 100644 index fd6ecaf101a..00000000000 --- a/snippets/visualbasic/VS_Snippets_WebNet/HttpUtility_ParseQueryString/vb/httputility_parsequerystring.aspx +++ /dev/null @@ -1,61 +0,0 @@ - -<%@ Page Language="VB" %> - - - - - - - HttpUtility ParseQueryString Example - - -
- Query string variables are: - - - - - diff --git a/snippets/visualbasic/VS_Snippets_WebNet/HttpUtility_ParseQueryString/vb/httputility_parsequerystring.vb b/snippets/visualbasic/VS_Snippets_WebNet/HttpUtility_ParseQueryString/vb/httputility_parsequerystring.vb new file mode 100644 index 00000000000..528c4df0ae3 --- /dev/null +++ b/snippets/visualbasic/VS_Snippets_WebNet/HttpUtility_ParseQueryString/vb/httputility_parsequerystring.vb @@ -0,0 +1,27 @@ +' + +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 + +' \ No newline at end of file diff --git a/xml/System.Web/HttpUtility.xml b/xml/System.Web/HttpUtility.xml index f0a70182299..527850b3e77 100644 --- a/xml/System.Web/HttpUtility.xml +++ b/xml/System.Web/HttpUtility.xml @@ -847,7 +847,7 @@ method uses format to parse the query string In the returned , 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 method uses format to parse the query string In the returned , 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 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)). @@ -857,8 +857,8 @@ ## Examples The following code example demonstrates how to use the method. Multiple occurrences of the same query string variable are consolidated in one entry of the returned . - :::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"::: ]]> @@ -922,7 +922,7 @@ , 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 , 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 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)).