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

Who is Participating?
Obadiah ChristopherConnect With a Mentor Commented:
Add a dll reference to System.Web to your project.
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:

Open in new window

It will return a instance of HttpContext class if is available from the context of your application.
Carlos VillegasFull Stack .NET DeveloperCommented:
Sorry, I meant: not a windows Forms Client
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

XK8ERAuthor Commented:
this is not an ASP app its a windows DDL file that its used with an exe file..
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");
Carlos VillegasFull Stack .NET DeveloperCommented:
Good point!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.