Solved

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

Posted on 2007-12-02
3
216 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

10 Experts available now in Live!

Get 1:1 Help Now