C# WebApi中的异步方法导致IIS ExecuteRequestHandler挂起
在我的WebApi 2控制器中有以下方法C# WebApi中的异步方法导致IIS ExecuteRequestHandler挂起,c#,iis,asynchronous,asp.net-web-api,C#,Iis,Asynchronous,Asp.net Web Api,在我的WebApi 2控制器中有以下方法 [Route("document/{documentGuid:Guid}/basic")] [DocumentName("label")] [HttpGet] public async Task<HttpResponseMessage> BasicDocument(Guid documentGuid) { byte[] data = await _documentsGenerator.CreateDocument(documentGu
[Route("document/{documentGuid:Guid}/basic")]
[DocumentName("label")]
[HttpGet]
public async Task<HttpResponseMessage> BasicDocument(Guid documentGuid)
{
byte[] data = await _documentsGenerator.CreateDocument(documentGuid);
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new ByteArrayContent(data);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = string.Format("document-{0}-basic.pdf", documentGuid)
};
return result;
}
[路由(“document/{documentGuid:Guid}/basic”)]
[文件名称(“标签”)]
[HttpGet]
公共异步任务基本文档(Guid文档Guid)
{
字节[]数据=等待_documentsGenerator.CreateDocument(documentGuid);
HttpResponseMessage结果=新的HttpResponseMessage(HttpStatusCode.OK);
结果.内容=新的ByteArrayContent(数据);
result.Content.Headers.ContentType=新的MediaTypeHeaderValue(“应用程序/八位字节流”);
result.Content.Headers.ContentDisposition=新的ContentDispositionHeaderValue(“附件”)
{
FileName=string.Format(“document-{0}-basic.pdf”,documentGuid)
};
返回结果;
}
当我从浏览器调用它下载文件时,我得到了该文件,但请求仍在IIS工作人员列表中挂起:
如果我从方法中删除async/await代码,一切正常。我执行什么样的异步操作也无关紧要。只要我使用
wait SomeMethod()
ExecuteRequestHandler就会挂起。原因可能是什么?最可能的原因是某些运行时没有在.NET 4.5(或更新版本)中运行
请确保:
web.config
中的属性httpRuntime.targetFramework
设置为适当的值(例如4.5
)看看是的,我的目标是.NET4.5,并且在Web.config中有targetFramework属性。但是,它可能与IIS或Windows有关,因为此错误发生在Windows 8.1和VS 2013上,而在Windows 10和VS 2015上,此问题不会发生