Solved

Using System.Encode() in C#

Posted on 2011-03-15
6
357 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
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

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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled

749 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