Solved

Using System.Encode() in C#

Posted on 2011-03-15
6
346 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
Comment Utility
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
Comment Utility
How do I use it?
0
 

Author Comment

by:newbieweb
Comment Utility
Encode(), not Decode()
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:newbieweb
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now