gpt4 book ai didi

c# - 命名空间在类中找到,但在 aspx 中找不到

转载 作者:行者123 更新时间:2023-11-30 12:23:41 31 4
gpt4 key购买 nike

我在使用命名空间 System.Net.Http 时遇到问题。

我想使用,例如HttpClient,来自命名空间 System.Net.Http。当我在 C# 类中使用 using System.Net.Http; 时,我可以很好地使用 HttpClient,但是当我尝试在 aspx 文件中导入命名空间时,如下所示:%@ Import Namespace="System.Net.Http"%> 它不会 regonize HttpClient:

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

我已经安装好了 this并通过执行 this 将其添加到我的引用资料中.

我如何使用,例如HttpClient,在我的 .aspx 文件中,就像我在 C# 类中使用它一样?

更新

这不是 Why should i include the namespace in each aspx page? 的副本,因为我不是在问我应该如何在每个类中包含一个 namespace 。

最佳答案

首先值得指出的是,您可能不应该这样做。您可能应该在 Page_Load 事件中准备好所需的数据,然后将其显示在 WebForms 页面上。如果你仍然想这样做,我很确定你有一个依赖程序集而不是 System.Web.HttpClient。查看您的 CodeBehind 页面,并确保在 CodeBehind 中每次使用时,所有导入都在 aspx 页面中。换句话说:

System.Web.HttpClient 依赖于您未引用的另一个程序集。

关于c# - 命名空间在类中找到,但在 aspx 中找不到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36032453/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com