【发布时间】:2014-10-09 07:33:03
【问题描述】:
我正在尝试运行 Test.aspx:
<%@ Page language="c#" EnableViewState="true" ContentType="text/html" Async="true" %>
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs E )
{
RegisterAsyncTask(new PageAsyncTask(BindData));
}
private async System.Threading.Tasks.Task BindData()
{
Response.Write("Hello?<br /><br />");
using (System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient())
{
Response.Write(await httpClient.GetStringAsync("http://www.google.com"));
}
Response.Write("<br /><br />Is this thing on?<br /><br />");
}
</script>
并收到此错误:
Test.aspx(14): error CS0234: The type or namespace name 'Http' does not exist in the namespace 'System.Net' (are you missing an assembly reference?)
System.Net.Http.dll 程序集在
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies
在 IIS 管理器中,基本设置的应用程序池是 ASP.NET v4.0(集成)。有人遇到过这种情况吗?
更新:我安装了 .Net 4.5.2 并添加了以下 web.config
<configuration>
<system.web>
<httpRuntime targetFramework="4.5" />
<compilation>
<assemblies>
<add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</assemblies>
</compilation>
</system.web>
</configuration>
它成功了。
【问题讨论】:
-
确保您在 .NET 4.5 中引用 System.Net.Http.dll
-
这是一个独立的 .aspx 页面,没有代码隐藏。它不是解决方案或项目的一部分,也不在 Visual Studio 中。添加 没有帮助。
-
要解决这个问题,我必须添加
和 到 web.config
标签: asp.net async-await dotnet-httpclient