简体   繁体   中英

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.

I tried everything that is mentioned in this post , but I keep getting a hidden div with the following message instead:

The Report Viewer Web Control HTTP Handler has not been registered in the application's web.config file. 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.

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.

I have RouteExistingFiles = false and ignored the following routes:

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

and disabled the BlockViewHandler by removing it from the webconfig.

I'm using Microsoft.ReportViewer for visual studio 2012 (ver 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.

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. 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

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.

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")

In this case, you're rendering a traditional web form as if it was a razor page. 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. You can open it in a new window/tab by using 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.

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). But, whichever format you choose, it will lack the report viewer interactitvity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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