Click here to Skip to main content
15,884,298 members
Articles / Web Development / ASP.NET

UrlBuilder Part II - Encoded QueryStrings

Rate me:
Please Sign up or sign in to vote.
4.65/5 (12 votes)
29 Sep 20057 min read 115.6K   602   65  
Taking UrlBuilder to the next level.
<%@ Page language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false" Inherits="CraigLabs.Web._Default" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>Default</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" Content="C#">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
	</HEAD>
	<body MS_POSITIONING="GridLayout">
		<form id="Form1" method="post" runat="server">
			<span style="FONT-SIZE: 18pt; FONT-FAMILY: verdana">UrlBuilder Examples</span>
			<br /><hr width="650" align=left />

<span style="FONT-SIZE: 10pt; FONT-FAMILY: verdana; font-weight: bold">DefaultEncoder</span><br />
<pre style="color: green">
private void DoDefaultEncoder() {
	string url = "http://localhost/CraigLabs.Web/Default.aspx?a=1&b=2&c=3";

	UrlBuilder builder = new UrlBuilder(url);

	builder.QueryString["d"] = "4";
	builder.QueryString["e"] = "5";
	builder.QueryString["f"] = "6";

	litDefaultEncoder.Text += builder.ToString();
}
</pre>
			<span style="FONT-SIZE: 8pt; FONT-FAMILY: verdana">
				<b>Output: </b><asp:Literal ID="litDefaultEncoder" Runat="server"></asp:Literal>
			</span>
			
			<br /><hr width="650" align=left />
			
<span style="FONT-SIZE: 10pt; FONT-FAMILY: verdana; font-weight: bold">Base64Encoder</span><br />
<pre style="color: green">
private void DoBase64Encoder() {
	string url = "http://localhost/CraigLabs.Web/Default.aspx?a=1&b=2&c=3";

	UrlBuilder builder = new UrlBuilder(url, new Base64Encoder());

	builder.QueryString["d"] = "4";
	builder.QueryString["e"] = "5";
	builder.QueryString["f"] = "6";

	litBase64EncoderEncoded.Text = builder.ToString();
	litBase64EncoderPlaintext.Text = builder.ToString("p");
}
</pre>
			<span style="FONT-SIZE: 8pt; FONT-FAMILY: verdana">
				<b>Output: </b><asp:Literal ID="litBase64EncoderEncoded" Runat="server"></asp:Literal>
				<br /><br />
				<b>Output: </b><asp:Literal ID="litBase64EncoderPlaintext" Runat="server"></asp:Literal>
			</span>
			
			<br /><hr width="650" align=left />
		</form>
	</body>
</HTML>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions