为什么使用ASP.NET的ReportViewer是时有时HttpContext.Current空? [英] Why is HttpContext.Current sometimes null when using ASP.NET ReportViewer?
问题描述
在我们的ASP.NET Web应用程序,我们有一个可以描述为实例每个请求,即该实例存储在 HttpContext.Current.Items <生命时间/范围服务/ code>集合。
In our ASP.NET Web Application, we have a service with a life-time/scope that can described as "instance per request" i.e. the instance is stored in the HttpContext.Current.Items
collection.
我们有过这样的间歇性问题的 HttpContext.Current
属性是空
期间从ASP.NET调用的ReportViewer
控制。有时它是空
,有时则不然。该行为可分期网站与一个开发机器上的不同,甚至不同的机器开发之间变化。
We have had this intermittent issue where the HttpContext.Current
property is null
during calls from the ASP.NET ReportViewer
control. Sometimes it is null
, sometimes it is not. The behaviour can be different on the staging website versus a dev machine, and even varies between different dev machines.
这将引起想使用我们的服务来抛出异常的报告。
This will cause a report which would like to use our service to throw an exception.
为什么 HttpContext.Current
属性空
?
为什么是间歇性的?
推荐答案
问题的根源似乎是报表查看器有时使用线程池中的线程来检索报表中定义数据集的数据。线程池中的线程不能访问该线程的 HttpContext.Current
实例服务于HTTP请求(的更多的在这个博客帖子信息)。
The source of the problem seems to be that the Report Viewer sometimes uses Thread Pool threads to retrieve data for DataSets defined in the report. Thread Pool threads cannot access the HttpContext.Current
instance of the thread servicing the HTTP request (more information in this blog post).
在我的情况的报告有一些报表定义数据集,每个对应的是 ObjectDataSource控件
定义的页面上。大量的调试后,我发现,该报告将检索的数据在服务HTTP请求在同一线程上的报表定义声明的第一个数据集。任何后续的DataSet会的或者的是主要的HTTP请求的线程的或的线程池线程上检索。然后,这些数据集以后会间歇性地抛出异常说 HttpContext.Current
为null。
The reports in my scenario had a number of DataSets in the report definition which each corresponded to an ObjectDataSource
defined on the page. After extensive debugging I found that the report would retrieve the data for the first DataSet declared in the report definition on the same thread that services the HTTP request. Any subsequent DataSets would either be retrieved on the main HTTP request thread or a Thread Pool thread. These subsequent DataSets would then intermittently throw exceptions saying that HttpContext.Current
was null.
似乎没有要或控制哪个线程中的DataSet会后第一个被检索的任何方式predict。
There does not seem to be any way to predict or control what thread a DataSet will be retrieved on after the first one.
这篇关于为什么使用ASP.NET的ReportViewer是时有时HttpContext.Current空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!