问题
The name 'HttpUtility' does not exist in the current context.
I'm a bit stuck here. I have using System.Web
at the top of my file, which has no error, and System.Web
is listed in my references. I tried double-clicking the reference, finding the UrlEncode
method in the object browser, and literally drag-and-dropping the method into my code, and it still can't find HttpUtility
. What am I missing?
Here is the code, boiled down:
using System.Web
string path = "path/to/file";
path = HttpUtility.UrlEncode(path);
Fully qualifying HttpUtility doesn't help either. It doesn't even show up in the auto-complete list. Only "AspNetHostingPermission" shows up.
回答1:
Look to me like you have another library in your solutions and that's where you are trying to access the HttpUtility. If that's correct, you need to add a reference to System.Web dll in your library.
Let me know if that was the case.
来源:https://stackoverflow.com/questions/9183435/asp-net-can-not-find-httputility