简体   繁体   English

SSRS报告查看器不能与ASP.NET MVC路由一起使用

[英]SSRS report viewer not working with asp.net mvc routing

I'm trying to use SSRS reporting with an Asp.net MVC website with local reports. 我正在尝试将SSRS报告与带有本地报告的Asp.net MVC网站一起使用。

I tried everything that is mentioned in this post , but I keep getting a hidden div with the following message instead: 我尝试了这篇文章中提到的所有内容,但是却不断显示以下消息来隐藏div:

The Report Viewer Web Control HTTP Handler has not been registered in the application's web.config file. 报表查看器Web控件HTTP处理程序尚未在应用程序的web.config文件中注册。 Add to the system.web/httpHandlers section of the web.config file, or add to the system.webServer/handlers section for Internet Information Services 7 or later. 添加到web.config文件的system.web / httpHandlers部分,或添加到Internet Information Services 7或更高版本的system.webServer / handlers部分。

The handlers are correctly added to the web config and reports will work if I navigate to the aspx page directly (by , but since view engine is not involved I cannot use any of razor helpers, this problem only occurs when I'm using routing. 处理程序已正确添加到Web配置中,并且如果我直接导​​航到aspx页面(通过,则报表将起作用),但是由于不涉及视图引擎,因此我无法使用任何剃刀助手,因此仅在使用路由时才会出现此问题。

I have RouteExistingFiles = false and ignored the following routes: 我有RouteExistingFiles = false并忽略了以下路由:

 {resource}.axd/{*pathInfo}; {resource}.aspx/{*pathInfo}; {resource}.ascx/{*pathInfo}; 

and disabled the BlockViewHandler by removing it from the webconfig. 和禁用BlockViewHandler从webconfig中删除。

I'm using Microsoft.ReportViewer for visual studio 2012 (ver 11.0.0.0) 我正在使用Visual Studio 2012的Microsoft.ReportViewer(版本11.0.0.0)

Edit There is this post from Scot Hanselman about using razor views with ASPX master pages, I'm doing the exact reverse, using aspx user control with Razor layout, but this Microsoft report viewer does not work with this approach. 编辑这个帖子从苏格兰人Hanselman的有关使用剃刀观点与ASPX母版页,我做的完全相反,使用剃刀布局ASPX用户控制,但此Microsoft报表查看器不使用这种方法的工作。

Because of your comments, I've found the reason because it's not working. 由于您的评论,我找到了原因,因为它无法正常工作。

I have a User control that uses the report viewer, and a aspx page that uses that user control to show the reports. 我有一个使用报表查看器的用户控件,以及一个使用该用户控件显示报表的aspx页面。 if I navigate directly to the report like: myhost/Views/Shared/ReportViewer.aspx it works, if I use routing like: myhost/report/myreport it wont work 如果我直接导​​航至报表,例如:myhost / Views / Shared / ReportViewer.aspx,它将起作用;如果我使用路由,如:myhost / report / myreport,它将无法正常工作

When you navigate directly to the page, it's rendered by the "traditional" web forms infrasctructure, so all the elements needed by the report viewer (view state, script manager and son on) are available, and the report viewer works fine. 当您直接导航到页面时,页面是由“传统” Web表单基础结构呈现的,因此报告查看器所需的所有元素(视图状态,脚本管理器和子菜单)均可用,并且报告查看器可以正常工作。

When you navigate using routing, form the comments: 使用路由导航时,形成以下注释:

yes creating a route that makes the reportviewer to be handled by an MVC controller which returns a razor view that renders report user control using Html.RenderPartial("ReportControl") 是,创建一条路由,使MVC控制器处理reportviewer,该控制器将返回一个剃刀视图,该视图使用Html.RenderPartial(“ ReportControl”)呈现报告用户控件。

In this case, you're rendering a traditional web form as if it was a razor page. 在这种情况下,您将呈现传统的Web表单,就好像它是一个剃须刀页面一样。 When you do this, all the infrastructure needed by the report viewer control is missing (particularly the view state), and thus it doesn't work. 当您这样做时,报告查看器控件所需的所有基础结构都将丢失(尤其是视图状态),因此它不起作用。

So, you need to show the report viewer page as a traditional web form. 因此,您需要将报告查看器页面显示为传统的Web表单。 You can open it in a new window/tab by using javascript. 您可以使用javascript在新窗口/标签中打开它。 If you still want to integrate it in an existing MVC page, the only solution is to use an <iframe> and render the report inside it. 如果您仍想将其集成到现有的MVC页面中,则唯一的解决方案是使用<iframe>并在其中呈现报表。

Another solution to integrate it directly in an MVC page would be to render the report using the Reporting Services web service, and sending the output to the browser (for example as a .jpg image or a PDF doc). 将其直接集成到MVC页面中的另一种解决方案是使用Reporting Services Web服务呈现报告,并将输出发送到浏览器(例如,以.jpg图像或PDF doc)。 But, whichever format you choose, it will lack the report viewer interactitvity. 但是,无论选择哪种格式,它都将缺乏报表查看器的交互性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM