Using System.Encode() in C#

Posted on 2011-03-15
Medium Priority
Last Modified: 2012-08-14
I need to encode a Uri with a few params and provide values. But I don't want to continue to struggle transating excape characters.

Could someone please explain how to use this?

I have the domain and wo variables:


Question by:newbieweb
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 10

Expert Comment

ID: 35139561
Server.UrlEncode() and Server.UrlDecode() exist expressly for this purpose.  Encode and send along your querystring, then decode when you request on the other side.

Author Comment

ID: 35139679
How do I use it?

Author Comment

ID: 35139683
Encode(), not Decode()
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 35139842
I was hoping for an example where you could use Encode with the two variables (and values) I posted above.
LVL 10

Accepted Solution

Nash2334 earned 2000 total points
ID: 35139862
If url is http://www.mysite.com?un=username&ts=timestamp

If you want to encode the ENTIRE url:

string url = "http://www.mysite.com?un=username&ts=timestamp";
string encodedUrl = Server.UrlEncode(url);

If you want to encode ONLY the username and timestamp:

string uname = "username";
DateTime timestamp = DateTime.Now;

string url = string.Format("http://www.mysite.com?un={0}&ts={1}", Server.UrlEncode(uname), Server.UrlEncode(tstamp.ToShortDateString());

Author Closing Comment

ID: 35142285

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question