Csharp/C#教程:返回HttpResponseMessage并配置Application Insights时,WebAPI响应永远不会完成分享


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

我有一个MVC5 / WebAPI2应用程序,自我创建Web项目以来已启用Application Insights。

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

public class TestController : ApiController { [HttpGet] [AllowAnonymous] async public Task ReadString(int id) { HttpResponseMessage response = Request.CreateResponse(); string str; using (HttpClient client = new HttpClient()) { Uri uri = new Uri("https://someurl.com/resource.rss"); str = await client.GetStringAsync(uri); } response.Content = new StringContent(str); response.Content.Headers.ContentLength = str.Length; return response; } } 

当我创建一个返回HttpResponseMessage的动作时,我注意到浏览器中有一个奇怪的行为(用Chrome和IE测试)。 具体来说,我的内容被返回到浏览器,但“忙”指示器从未停止旋转,直到我点击停止按钮,或停止了Web服务器(Visual Studio 2013)。

我已经validation上述方法在没有Application Insights的Web应用程序中按预期工作。 具体来说,一旦数据返回到浏览器,响应就会结束。 当使用Application Insights将以下方法添加到新创建的应用程序时,会遇到前面描述的行为。

有什么想法吗?

这是由ASP.NET请求管道中抛出的NullReferenceException引起的。 Microsoft.ApplictionInsights.Web包正在处理HttpApplication.PreSendRequestHeaders事件,该事件会触发此问题。 在即将发布的0.17版本中,我们已将Application Insights代码更改为不再处理此事件,您不应再看到此问题。

上述就是C#学习教程:返回HttpResponseMessage并配置Application Insights时,WebAPI响应永远不会完成分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/951672.html

(0)
上一篇 2021年11月18日
下一篇 2021年11月18日

精彩推荐