Solved

Where is UrlEncode method if I need to call it from a business object class?

Posted on 2007-12-02
3
211 Views
Last Modified: 2012-06-27
I have an ASP.NET/C# application. In a method in one of the business object classes, I need to make an HttpWebRequest to a website that returns an XML response. I need to URL-encode the request, but the System.Web namespace in an ".cs" business object class does not include the needed HttpUtility class that it does in the System.Web namespace if called directly from the ".aspx.cs" code-behind. I could hack a work-around to pass the string value back to the .aspx.cs page and then pass the url-encoded value back to the .cs class, but that doesn't seem very elegant, and I don't think that I should have to, since I may need to use this method from other places.

So, my question is, where do I find a UrlEncode method that I can use?
0
Comment
Question by:DanielBorson
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 125 total points
ID: 20392646
Include the name using using:

using System.Web;

or specify the full namespace:

... = System.Web.HttpUtility.UrlEncode(...)

If you don't have a reference to the system.web.dll, you need to add it. Right click on references in the project in the solution explorer, and select Add Reference. Add the System.Web library.
0
 

Author Comment

by:DanielBorson
ID: 20392899
That was it. I was seeing a "System.Web", so I thought I had that reference, but it only had three classes in it, so I'm not sure what that was, but it wasn't the System.Web I needed. Adding the reference to the project was what it needed. Thanks.
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20393043
There are some classes in the System.Web namespace in the mscorlib.dll, so they are always there. Although most libraries have their own namespace, there is nothing that keeps a namespace from being spread across several libraries.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

20 Experts available now in Live!

Get 1:1 Help Now