开发者

How can i reference Server.UrlEncode in an ASP.NET class?

I have created an ASP.NET class. In that class i would like to use the Server.UrlEncode.

Why intellisense is not helping me at all and instead of Server.UrlEncode it dis开发者_Go百科plays the HttpServerUtility?

I have already a reference to system.web


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

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


Because the .Server property of the page is an instance of HttpServerUtility class.

http://msdn.microsoft.com/en-us/library/system.web.ui.page.server.aspx

To use UrlEncode method outside the page, use the HttpUtility class.

http://msdn.microsoft.com/en-us/library/1e55w41w.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜