简体   繁体   中英

Namespace is found in class, but not in aspx

I'm having trouble with the namespace System.Net.Http .

I want to use, eg HttpClient, from the namespace System.Net.Http . When I use using System.Net.Http; in a C# class, I can use HttpClient just fine, but when I try to import the namespace in an aspx file, like this: %@ Import Namespace="System.Net.Http" %> it won't regonize HttpClient:

The type or namespace name 'HttpClient' could not be found (are you missing a using directive or an assembly reference?)

I've already installed it like this and added it to my references by doing this .

How do I use, eg HttpClient, in my .aspx file like I use it in a C# class?

UPDATE

This is not a duplicate of Why should i include the namespace in each aspx page? , because I'm not asking how I'm supposed to include a namespace in every class.

First it is worth pointing out that you probably shouldn't do this. You should probably prepare the data you need in the Page_Load event and just display it on the WebForms page. If you still want to do it this way, I am pretty sure what is happening is that you have a dependent assembly other than System.Web.HttpClient. Have a look at your CodeBehind page and make sure all imports are there in the aspx page for every using in the CodeBehind. In other words:

System.Web.HttpClient depends on another assembly you are not referencing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM