Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 631
  • Last Modified:

.NET 4.0 urlencode in a class library

I a currently writing a .NET port of some classes originally written in PHP and I need to encode some strings to be safe for use in a URL. The catch is that I am writing this in a class library so I do not have access to system.web.httputility. Everything I have seen online is based around web applications that have access to such features. What I need is a url encoding functions that will function in a class library. Does .NET have such a feature?

Thanks,
Dan
0
Daniel-B
Asked:
Daniel-B
  • 4
  • 4
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
You could always just add a reference to System.Web to your library.
0
 
Daniel-BAuthor Commented:
I do have a reference to system.web, I still dont have access to httputility
0
 
CodeCruiserCommented:
One option is to reference the System.Web and then use the urlencode method

http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/12fcaefa-75a9-4fc5-bf06-d5c19322b7b9

The other option is this

http://www.west-wind.com/weblog/posts/617930.aspx
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Carl TawnSystems and Integration DeveloperCommented:
If you have a reference to System.Web, then HttpUtility is there.  How are you trying to access it?
0
 
Daniel-BAuthor Commented:
I've tried System.Web.HttpUtility and HttpUtility. Intellisense has no knowledge of it of any kind.
0
 
Carl TawnSystems and Integration DeveloperCommented:
That's odd. If you have added a reference to the assembly then it should be recognising it, even if it is a class library.

Are you getting any intellisense response when you access System.Web at all?
0
 
Daniel-BAuthor Commented:
Yes, I get:
aspNetHostingPermission
aspNetHostingPermissionAttribute
aspNetHostingPermissionLevel
0
 
Carl TawnSystems and Integration DeveloperCommented:
In that case you can't have added a reference to the System.Web assembly. The three items you mention are part of the System.Web namespace, but aren't part of the System.Web assembly itself.

Right-click your project, choose Add Reference, then on the .Net tab scroll down to System.Web, select it then click OK. You should then get access to System.Web.HttpUtility
0
 
Daniel-BAuthor Commented:
Works perfect, thanks.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now