Blog

Going to use Server.UrlEncode inside App_Code Class?

Posted by Deepak Kumar Verma Blogs | ASP.NET Programming Nov 22, 2012
Server.UrlEncode is used to encode a string. Here, I am going to discuss how to use it in a Class inside App_Code directory in Asp.net.
Server.UrlEncode is used to encode a string. Often, it is used to encode urls.

Method "Server.UrlEncode" is working fine in asp.net pages or controls, but when you try to use it in a class written inside "App_Code" folder, for eg.

Server.UrlEncode("Some String");

it shows an error "The name 'Server' does not exist in the current context".

How to resolve it?

simply use the following code instead:

HttpContext.Current.Server.UrlEncode("Some String");

post comment
     
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts