How to use HttpServerUtility?

G

Guest

I have a dll file that i am trying to use the Server.Encode function.
so i have added a reference to System.Web;

but when im trying to delcare:
HttpServerUtility mServer = new HttpServerUtility();
return mServer.HtmlEncode(strValue);

i get the following error:
Error The type 'System.Web.HttpServerUtility' has no constructors defined

Is there a list to find what constructors to use? how do you know how to
declare if you dont have any references or examples of this?
 
K

Kevin Spencer

The HttpServerUtility.HtmlEncode method is static. It doesn't require an
instance. Just call HttpUtility.HtmlEncode(whatever).

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
We got a sick zebra a hat,
you ultimate tuna.
 
H

Hans Kesting

I have a dll file that i am trying to use the Server.Encode function.
so i have added a reference to System.Web;

but when im trying to delcare:
HttpServerUtility mServer = new HttpServerUtility();
return mServer.HtmlEncode(strValue);

i get the following error:
Error The type 'System.Web.HttpServerUtility' has no constructors defined

Is there a list to find what constructors to use? how do you know how to
declare if you dont have any references or examples of this?

You can access it via System.Web.HttpContext.Current.Server, BUT: this
will only work if there really *is* an HttpContext (else Current is
null).

Hans Kesting
 
Joined
Jul 4, 2008
Messages
1
Reaction score
0
do like the following:

HttpServerUtility Server = HttpContext.Current.Server;

then u can use the Server.HtmlEncode ..... etc methods and functions...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top