Nae*_*raz 10
您可以通过HttpContext对象访问该功能.我猜你的类在一个类库中,你应该总是检查你有一个上下文,以防你的代码在Web上下文之外被调用.试试这个:
if (HttpContext.Current != null)
{
string sEncondedBit = HttpContext.Current.Server.UrlEncode("text & more txt");
}
Run Code Online (Sandbox Code Playgroud)
因为.Server页面的属性是HttpServerUtility类的实例.
http://msdn.microsoft.com/en-us/library/system.web.ui.page.server.aspx
要UrlEncode在页面外使用方法,请使用HttpUtility该类.
http://msdn.microsoft.com/en-us/library/1e55w41w.aspx