Using System.Encode() in C#

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:


newbiewebSr. Software EngineerAsked:
Who is Participating?
Nash2334Connect With a Mentor Commented:
If url is

If you want to encode the ENTIRE url:

string url = "";
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("{0}&ts={1}", Server.UrlEncode(uname), Server.UrlEncode(tstamp.ToShortDateString());
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.
newbiewebSr. Software EngineerAuthor Commented:
How do I use it?
Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

newbiewebSr. Software EngineerAuthor Commented:
Encode(), not Decode()
newbiewebSr. Software EngineerAuthor Commented:
I was hoping for an example where you could use Encode with the two variables (and values) I posted above.
newbiewebSr. Software EngineerAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.