返回HttpResponseMessage时,Web API响应永远不会完成

时间:2015-07-12 04:03:30

标签: c# .net asp.net-web-api asp.net-web-api2

this question类似,从Web API返回手动格式化的html时,echo "Example " . $example; 永远不会完成。所有内容都正确传输,但响应没有关闭,浏览器加载轮一直在旋转。

不同之处在于我没有使用Application Insights。

HttpResponseMessage

此html不适用于浏览器使用,但适用于Excel数据导入。就像浏览器一样,Excel无法获取数据,因为它无法完成。

有什么想法吗?

更新

使用自定义public async Task<HttpResponseMessage> GetHtml(string id) { var asset = await ... var builder = new StringBuilder(); builder.Append("<!DOCTYPE HTML>"); // ... return new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(builder.ToString(), Encoding.UTF8, "text/html") }; } 有效。文档here.

MediaTypeFormatter

没有张贴作为答案,因为我无法说明原因。

更新2

删除存储库调用以获取db记录并简单地返回模拟html文档时,http响应正确关闭。抛出异常并正确检索db记录。 Unity会解决依赖关系。

0 个答案:

没有答案