How can I refer to Server.UrlEncode in an ASP.NET class?

I created an ASP.NET class. In this class I would like to use Server.UrlEncode.

Why does intellisense not help me at all, but instead Server.UrlEncodedisplay HttpServerUtility?

I already have a link to system.web

+3
source share
2 answers

You can access this function through an HttpContext object. I think your class is in a class library, in which you should always check that you have a context if your code is called outside of the web context. Try the following:

if (HttpContext.Current != null)
{
    string sEncondedBit = HttpContext.Current.Server.UrlEncode("text & more txt");
}
+10
source

Source: https://habr.com/ru/post/1765487/


All Articles