归国的Htt presponseMessage和应用洞察配置时的WebAPI响应永远不会完成 [英] WebAPI Response never completes when returning HttpResponseMessage and Application Insights is configured

查看:229
本文介绍了归国的Htt presponseMessage和应用洞察配置时的WebAPI响应永远不会完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这已经自从我创建的Web应用程序项目洞察启用的MVC5 / WebAPI2应用。

I have an MVC5/WebAPI2 application which has had Application Insights enabled since I created the web project.

的WebAPI返回对象(例如字符串,模型对象)按预期的方式返回的方法 - 序列化为JSON或XML

WebApi methods that return objects (e.g. string, model objects) are returned as expected - serialized into JSON or 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;
    }
}

当我创建了一个返回的Htt presponseMessage一个动作,我注意到在浏览器(Chrome浏览器和IE测试)一个奇怪的行为。具体来说,我含量返回给浏览器,但忙指示灯不停止旋转,直到我打的停止按钮,或停止Web服务器(的Visual Studio 2013)。

When I created an action that returns an HttpResponseMessage, I noticed a strange behavior in the browser (tested with Chrome and 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应用程序。具体地,一旦数据被返回到浏览器时,反应结束。当下面的方法添加到具有应用洞察刚创建的应用程序,行为描述previously遇到。

I've verified that the method above works as expected in a web app without Application Insights. 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.

有什么想法?

推荐答案

这是由引起的NullReferenceException 甩在了ASP.NET请求管道。该Microsoft.ApplictionInsights.Web包处理<一个href=\"https://msdn.microsoft.com/en-us/library/system.web.httpapplication.$p$psendrequestheaders.aspx\"相对=nofollow>的HttpApplication。preSendRequestHeaders 的事件,该事件引发的问题。在即将到来的0.17版本中,我们已经改变了应用程序洞察code不再处理此事件,你不应该再看到这个问题。

This is caused by a NullReferenceException thrown in the ASP.NET request pipeline. The Microsoft.ApplictionInsights.Web package is handling the HttpApplication.PreSendRequestHeaders event, which triggers the problem. 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.

这篇关于归国的Htt presponseMessage和应用洞察配置时的WebAPI响应永远不会完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆