[英]WebAPI Response never completes when returning HttpResponseMessage and Application Insights is configured
I have an MVC5/WebAPI2 application which has had Application Insights enabled since I created the web project. 我有一个MVC5 / WebAPI2应用程序,自我创建Web项目以来已启用Application Insights。
WebApi methods that return objects (eg string, model objects) are returned as expected - serialized into JSON or XML. WebApi返回对象的方法(例如字符串,模型对象)按预期返回 - 序列化为JSON或XML。
public class TestController : ApiController
{
[HttpGet]
[AllowAnonymous]
async public Task<HttpResponseMessage> ReadString(int id) {
HttpResponseMessage response = Request.CreateResponse();
string str;
using (HttpClient client = new HttpClient()) {
Uri uri = new Uri("http://someurl.com/resource.rss");
str = await client.GetStringAsync(uri);
}
response.Content = new StringContent(str);
response.Content.Headers.ContentLength = str.Length;
return response;
}
}
When I created an action that returns an HttpResponseMessage, I noticed a strange behavior in the browser (tested with Chrome and IE). 当我创建一个返回HttpResponseMessage的动作时,我注意到浏览器中有一个奇怪的行为(用Chrome和IE测试)。 Specifically, my content was returned to the browser, but the "busy" indicator never stopped spinning until I hit the Stop button, or stopped the web server (Visual Studio 2013).
具体来说,我的内容被返回到浏览器,但“忙”指示器从未停止旋转,直到我点击“停止”按钮或停止了Web服务器(Visual Studio 2013)。
I've verified that the method above works as expected in a web app without Application Insights. 我已经验证上述方法在没有Application Insights的Web应用程序中按预期工作。 Specifically, once the data is returned to the browser, the response ends.
具体来说,一旦数据返回到浏览器,响应就结束了。 When the method below is added to a freshly-created app with Application Insights, the behavior described previously is encountered.
当使用Application Insights将以下方法添加到新创建的应用程序时,会遇到前面描述的行为。
Any thoughts? 有什么想法吗?
This is caused by a NullReferenceException
thrown in the ASP.NET request pipeline. 这是由ASP.NET请求管道中抛出的
NullReferenceException
引起的。 The Microsoft.ApplictionInsights.Web package is handling the HttpApplication.PreSendRequestHeaders event, which triggers the problem. Microsoft.ApplictionInsights.Web包正在处理HttpApplication.PreSendRequestHeaders事件,该事件会触发此问题。 In the upcoming 0.17 release we have changed the Application Insights code to no longer handle this event and you shouldn't see this problem anymore.
在即将发布的0.17版本中,我们已将Application Insights代码更改为不再处理此事件,您不应再看到此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.