Solved

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

Posted on 2007-12-02
3
222 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 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