Solved

Using System.Encode() in C#

Posted on 2011-03-15
6
356 Views
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:

un=username
ts=timeastamp

Thanks,
newbieweb
0
Comment
Question by:newbieweb
  • 4
  • 2
6 Comments
 
LVL 10

Expert Comment

by:Nash2334
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.
0
 

Author Comment

by:newbieweb
ID: 35139679
How do I use it?
0
 

Author Comment

by:newbieweb
ID: 35139683
Encode(), not Decode()
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

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

Accepted Solution

by:
Nash2334 earned 500 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());
0
 

Author Closing Comment

by:newbieweb
ID: 35142285
Thanks!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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