Missing images on Crystal Reports in ASP.NET

We use Crystal Reports as our reporting tool on many of our custom applications. It works great, as far as reporting tools go, but when it comes to adding images to the reports, things can get a bit... interesting? With reporting tools being more geared towards rendering textual information, there's several hoops you need to jump through in order to get those pretty visuals working.

Adding images to the report itself is trivial. Simply right-click on the design surface, go to Insert and then Picture. From the "Open File" dialog, select the image you want & click Open. The report then adds an OLE Object to the design surface, which you can then manipulate as you need.

But due to a couple of things, you may find that when the report is rendered in your application, all you see where the image should be is: [Image]. A bit of a let-down that...

Possible Solutions:

The first thing to check is whether the Crystal Reports Image Handler has been included. This handler configuration doesn't seem to be added to the web.config by default, so open it up & look at the <httpHandlers> element. You need the following there:

<add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>

Also, check the <handlers> element in the <system.webServer> parent node, as the handler needs to be added there as well:

<add name="CrystalImageHandler.aspx_GET" verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" preCondition="integratedMode"/>

 These are the easiest to miss, and the cause of most images not displaying.

 Issue in ASP.NET MVC

If you are using Crystal Reports in ASP.NET MVC, the images may still fail to load. This is because the ASP.NET MVC routing engine is trying to map the resource request for the Image Handler to a controller action & since it can't, returns a 404 status.

To verify this, open your browsers developer tools & look in the network tab. You should see something similar to the following:


The answer is to tell the ASP.NET MVC routing engine to ignore requests for this resource. To do so, open up your routing configuration code (this can be either in the RouteConfig.cs file in the App_Start directory, or directly in the Application_Start event in Global.asax if your solution was created using an older Visual Studio MVC template).

There should already be an ignore for .axd resources. Add the following ignore rule:

routes.IgnoreRoute("{*allaspx}", new { allaspx = @".*(CrystalImageHandler).*" });

 And voila, MVC doesn't take control of your image requests anymore and you have picture-filled reports being generated.