Connecting Tech Pros Worldwide Forums | Help | Site Map

URL Encoding Without using HttpServerUtil

Newbie
 
Join Date: Aug 2008
Posts: 3
#1: Aug 27 '08
I am a C# .Net developer who has been involved with the development of a framework library used within our company. The framework is being developed against .Net version 2.0. One question I have regarding .Net is the facility for URLEncoding of data. I am aware of the HttpServerUtil class. This class however is only really available to you when using ASP .Net. It doesn't seem to be possible to instantiate it outside of ASP. This is quite annoying given that the ability to URL Encode a string can be useful for applications other than just web sites. In Java URL Encoding and URL Decoding are available via a pair of utility classes in the java.net package. I wondered if .Net might have some equivalent to them. Whenever I search for information about URL Encoding in ,Net I just keep finding information about the HttpServerUtility class. Is there another way of URL encoding (besides having to write my own URL Encoding utility class)?

balabaster's Avatar
Moderator
 
Join Date: Mar 2007
Location: Canada
Posts: 757
#2: Aug 27 '08

re: URL Encoding Without using HttpServerUtil


Is this what you're looking for? I think it does just about the same thing as the ServerEncode method found in the HttpServerUtility class.

Expand|Select|Wrap|Line Numbers
  1. Dim OutStr As String = System.Uri.EscapeDataString("Hello World This is my test String; with \ [ special * chars")
  2.  
Expand|Select|Wrap|Line Numbers
  1. string OutStr = System.Uri.EscapeDataString("Hello World This is my test String; with \ [ special * chars");
  2.  
balabaster's Avatar
Moderator
 
Join Date: Mar 2007
Location: Canada
Posts: 757
#3: Aug 27 '08

re: URL Encoding Without using HttpServerUtil


Thanks Plater... I obviously didn't read that closely enough before hitting submit
Newbie
 
Join Date: Aug 2008
Posts: 3
#4: Aug 28 '08

re: URL Encoding Without using HttpServerUtil


Thank you. That is usefull.

I am wondering now if there is also an equivalent to the HtmlEncode method somewhere else but I am going to have a look around and see what I can find.
Newbie
 
Join Date: Aug 2008
Posts: 3
#5: Aug 28 '08

re: URL Encoding Without using HttpServerUtil


Quote:

Originally Posted by carljokl

Thank you. That is usefull.

I am wondering now if there is also an equivalent to the HtmlEncode method somewhere else but I am going to have a look around and see what I can find.

Never Mind. I found it is in the HttpUtility class as a static method.
Reply