5

I am having trouble with Crystal Reports when using charts and images which use CrystalImageHandler.aspx. The image cannot display and I suspect this is due to a problem with MVC routing.

The path image path is similar to this:

src="/CrystalImageHandler.aspx?dynamicimage=cr_tmp_image_a8301f51-26de-4869-be9f-c3c9ad9cc85e.png"

With the URL similar to this:

localhost:01234/ViewCrystalReports.aspx?id=50

The image cannot be found prumably because it's looking in a non-existant directory. How can I change the path CrystalImageHandler.aspx is located at? I think if I were to reference from the root the problem would be solved but anything I change in Web.Config fails to work.

I should mention this is on a conventional aspx page, not a view etc

Damien
  • 13,927
  • 14
  • 55
  • 88
  • 1
    Can you create the image from code? Might be easier to just create a page that will generate the image in the handler and return it as a FileResult/StreamResult/WhateverResult. –  Jan 05 '10 at 12:53
  • Hello Damien, This might be slightly off topic, but how was your experience using MVC with Crystal Reports? We are on the verge of creating a huge application on MVC with some extensive reporting. Do you think its a viable solution? also did you use reports in webforms (side by side with mvc) or streamed reports at run-time? – neebz Oct 14 '10 at 11:28
  • Possible duplicate of [CrystalImageHandler.aspx not found](http://stackoverflow.com/questions/11357854/crystalimagehandler-aspx-not-found) – bummi Dec 17 '15 at 08:05

5 Answers5

7

I solve this problem editing Web.Config file

Insert the following line:

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

*take care with write your number version (Version=xx.x.xxxx.x)

cmujica
  • 1,304
  • 1
  • 18
  • 27
  • I needed to add two more things to make it go. I somehow included Crystal in my project and it added the httpHandler, but it added the following bit at the end: `preCondition="integratedMode,runtimeVersionv4.0` I changed this to runtimeVersion2.0 The other thing was the folder `C:\inetpub\wwwroot\aspnet_client\system_web` had a folder for 2_0_50727, and I duplicated its contents into 4_0_30319 I assume the runtimeVersion2.0 refers to the fact that CrystalDecisions.Web.CrystalImageHandler is a .Net 2 assembly, while the file folder 4_0_30319 is referenced by ASP.NET 4.0 – erict Mar 08 '12 at 14:45
2

Figured it out. The routing was interfering with the CrystalImageHandler.aspx link that was being generated. Global.aspx has the following line to tell the routing engine to ignore resource files:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

but this isn't a conventional resource file, it's an aspx file for some reason (anyone know why?)

adding this fixed it:

  routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
Damien
  • 13,927
  • 14
  • 55
  • 88
2
public class CrystalImageHandlerController : Controller
{
    //
    // GET: /Reports/CrystalImageHandler.aspx

    public ActionResult Index()
    {
        return Content("");
    }

    protected override void OnActionExecuted(ActionExecutedContext filterContext)
    {

        var handler = new CrystalDecisions.Web.CrystalImageHandler();
        var app = (HttpApplication)filterContext.RequestContext.HttpContext.GetService(typeof(HttpApplication));
        if (app == null) return;

        handler.ProcessRequest(app.Context);

    }
}

This controller will invoke the handler. Just add a route to this as CrystalImageHandler.aspx, it can also be used with any sub path you'd like (in this case /reports). Something I could NEVER get the handler to do via configuration.

Nick Daniels
  • 922
  • 8
  • 13
0

To view in local machine,you will add the following code in web config

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

...............................

<appSettings>       
<add key="CrystalImageCleaner-AutoStart" value="true" />
<add key="CrystalImageCleaner-Sleep" value="60000" />
<add key="CrystalImageCleaner-Age" value="120000" />    
</appSettings>

The following code is for displaying in server

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

:) I will solve that problem in adding in web config

Community
  • 1
  • 1
Su Su
  • 1
0

It's because the routing was interfering with the CrystalImageHandler.aspx. So either in Global.asax or routeConfig file we can ignore route for .aspx extension files. You can ignore .aspx extension route by adding following line.

routes.IgnoreRoute("{allaspx}", new {allaspx=@"..aspx(/.*)?"});

Anuruddha
  • 3
  • 2