• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 996
  • Last Modified:

The name 'HttpUtility' does not exist in the current context

hello there,
I have a little issue with a DDL file that I am trying to make.. at the beginning I have this
using System.Web;
but then when I try to use HttpUtility like this I get the error
fields[i] = HttpUtility.UrlEncode((string)e.Key) + "=" + HttpUtility.UrlEncode((string)e.Value);

im trying to build it with Targed FrameWork 4.0 with no luck, what can I do?

Open in new window

0
XK8ER
Asked:
XK8ER
  • 4
1 Solution
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Hello, you must run your code from the aspnet server, not a windows form server, you can check is a valid HttpContext is available by using:
System.Web.HttpContext.Current

Open in new window


It will return a instance of HttpContext class if is available from the context of your application.
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Sorry, I meant: not a windows Forms Client
0
 
XK8ERAuthor Commented:
this is not an ASP app its a windows DDL file that its used with an exe file..
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Carlos VillegasFull Stack .NET DeveloperCommented:
Ok, if you want to use the UrlEncode method, you can use the System.Web.HttpServerUtility class, make an instance of this, like:
System.Web.HttpServerUtility myUtil = new System.Web.HttpServerUtility();
string urlEncoded = myUtil.UrlEncode("MyUrlToEncode");
0
 
informaniacCommented:
Add a dll reference to System.Web to your project.
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Good point!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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