Why are my Crystal Report and Viewer invisible in web form in MVC application?

I copy the code from the MVC 3 sample application to my new MVC 4 application. The code sets the report parameters to the session, that is, the report name and report data, and then calls the .aspx page with only CrystalReportViewer to show the report:

public class ReportController : Controller { public ActionResult Terminal() { Session["ReportName"] = "Terminal.rpt"; using (var sqn = new SqlConnection("Data Source=(Local);Initial Catalog=ParkPay;Integrated Security=SSPI;MultipleActiveResultSets=True;")) { var adap = new SqlDataAdapter("select * from parkpay.Terminal", sqn); var dt = new DataTable(); adap.Fill(dt); Session["ReportData"] = dt; } return RedirectToAction("ShowReport", "AspxReportViewer"); } } public class AspxReportViewerController : Controller { public void ShowReport() { Response.Redirect("~/AspxForms/ReportViewer.aspx"); } } 

Web Form:

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReportViewer.aspx.cs" Inherits="ParkPay.Reports.Crystal.AspxForms.ReportViewer" %> <%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form" runat="server"> <CR:CrystalReportViewer ID="CrystalReportViewer" runat="server" AutoDataBind="true" /> </form> </body> </html> 

The two projects β€” mine and the example β€” are almost identical, but when I invoke a report action such as Terminal in my project, all I get is an empty page. It has a Crystal viewer on it, which is a div full of JavaScript methods beyond my level.

The main work is done in the code for ReportViewer.aspx :

 protected void Page_Load(object sender, EventArgs e) { var reportDoc = new ReportDocument(); var reportName = Session["ReportName"].ToString(); var dataSource = Session["ReportData"] as DataTable; var reportPath = Path.Combine(Server.MapPath("~/Reports"), reportName); reportDoc.Load(reportPath); reportDoc.SetDataSource(dataSource); CrystalReportViewer.ReportSource = reportDoc; } 

This is identical both in the example and in my project. If I copy one of my reports into a sample project, it works just fine. Both web.config files look the same. In the sample report, there are no "special" files not in mine. The only obvious difference is my project is the launch project in a small solution, where the sample project is autonomous. In the decision, but only there.

What could be wrong with mine, or what's the difference? I'm thinking of just moving all my reports to an example and accessing it from my project.

NOTE. The JavaScript console shows these errors:

 Failed to load resource: the server responded with a status of 404 (Not Found): http://localhost:17441/aspnet_client/system_web/4_0_30319/crystalreportviewers13/js/crviewer/crv.js 

and

 Failed to load resource: the server responded with a status of 404 (Not Found): http://localhost:17441/aspnet_client/system_web/4_0_30319/crystalreportviewers13/js/crviewer/images/style.css 

and two

 Uncaught ReferenceError: bobj is not defined: ReportViewer.aspx:56 ReportViewer.aspx:64 
+4
source share
2 answers

Yeah, old bobj is not defined !

This means that you are running ASP on another site from the default site in IIS. When you install Crystal Reports, it puts a bunch of files in C:\Inetpub\wwwroot\aspnet_client , which are necessary for the report viewer to work.

Decision. Copy the crystal files below C:\Inetpub\wwwroot\aspnet_client to the root folder of your site.

To get the correct path, go to IIS Manager> Sites> [your site]> right-click> Website Management> Advanced Settings ...> Physical Path. The actual files you need are below wwwroot\aspnet_client\system_web\[framework version]\crystalreportviewers13 , but it’s usually easiest to copy the entire aspnet_client folder from the default website to your website’s website.

+8
source

If you go to the wwwroot folder and drag the aspnet_client folder into your project, it will add all the files.

C: \ Inetpub \ Wwwroot

I am still working on making this work work, as doing this is not enough.

It seems to be the best article on the topic I've found so far: http://scn.sap.com/community/crystal-reports-for-visual-studio/blog/2011/01/12/how-do-i- resolve-bobj-is-undefined-issue

However, I have now tried steps 1 and 4, but still have not been successful ...

The following are solutions to the above scenarios:

1. Connect the "crystalreportviewers12" folder to "C: \ Inetpub \ wwwroot \ system_web \ 2_0_50727" in the "Default Web Site" section of the Custom Website Directory in IIS. Or create a virtual directory by specifying the aspnet_client folder in the user website directory.

2. In IIS Manager, select Application Pool and Basic Settings. In managed pipeline mode, change the Integrated Mode mode to Classic.

3. The value of resoureURI should be "~ / crystalreportviewers12" not "/ crystalreportviewers12".

4. Copy the CrystalReportViewers12 folder from "C: Program Files \ Business Objects \ Common \ 4.0" and paste it into "C: \ Windows \ Microsoft.NET \ Framework \ v3.5 \ ASP.NETClientFiles".

Note. The structure may vary depending on the version of Visual Studio you are using.

My mistake:

0x800a1391 - JavaScript runtime error: "bobj" - undefined

 bobj.crv.stateManager.setComponentState('CrystalReportViewer1__UI',eval('('+document.getElementById('__CRYSTALSTATECrystalReportViewer1').value+')')); 

Somehow I seem to have come across different versions. VS wants to use 4_6_30, but I seem to have folders for 4_0_30319 ...

So while playing, I can get him to reset the bobj error, but it still does not display the report viewer. If you specify a report, now I just get that the report download failed ... and yet I let her create a new report via VS ...

0
source

Source: https://habr.com/ru/post/1495147/


All Articles