简体   繁体   English

返回HttpResponseMessage并配置Application Insights时,WebAPI响应永远不会完成

[英]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.

相关问题 返回HttpResponseMessage时的WebAPI Gzip - WebAPI Gzip when returning HttpResponseMessage 返回带有批处理响应的HttpResponseMessage - Returning an HttpResponseMessage with a batch response HttpResponseMessage不返回任何响应? - HttpResponseMessage Not Returning any response? IActionFilter返回一个新的Task <HttpResponseMessage>永远不会返回 - IActionFilter returning a new Task<HttpResponseMessage> never returns 使用Application Insights时,AreaRegistration.RegisterAllAreas()永远不会完成 - AreaRegistration.RegisterAllAreas() never finishes when using Application Insights 使用WebAPI HttpResponseMessage时下载文件提示 - Download file prompt when using WebAPI HttpResponseMessage 返回Task时,DelegatingHandler挂起<HttpResponseMessage> - DelegatingHandler hangs when returning Task<HttpResponseMessage> Application insights 读取响应正文 - Application insights read response body Net Core 2中的应用程序见解WebApi - 共享上下文属性 - Application Insights in Net Core 2 WebApi - Share Context To Append Properties WebAPI2 + Angular http GET-返回IEnumerable <Categories> 。 无法序列化内容类型为&#39;application / json的响应主体 - WebAPI2 + Angular http GET - returning IEnumerable<Categories>. failed to serialize the response body for content type 'application/json
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM