我正在尝试运行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>
然后它就起作用了。