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:

un=username
ts=timeastamp

Thanks,
newbieweb
newbiewebSr. Software EngineerAsked:
Who is Participating?
 
Nash2334Connect With a Mentor Commented:
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());
0
 
Nash2334Commented:
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.
0
 
newbiewebSr. Software EngineerAuthor Commented:
How do I use it?
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
newbiewebSr. Software EngineerAuthor Commented:
Encode(), not Decode()
0
 
newbiewebSr. Software EngineerAuthor Commented:
I was hoping for an example where you could use Encode with the two variables (and values) I posted above.
0
 
newbiewebSr. Software EngineerAuthor Commented:
Thanks!
0
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.