As some of you know, the latest release of CR for Visual Studio 2013 has an issue when used in a web project that uses the latest .NET 4.5.1 code. The issue is that images don't get displayed, in the web viewer. SAP is working on a fix, but until then, here's a workaround. I posted this in another thread, but it's buried pretty deep in the thread, so I thought I'd raise its visibility.
Because of the way this forum software works, I recommend copying this into Notepad or something like that, if you want to look at it:
This is for an ASP.Net 4.5.1 Web Forms app, using Visual Studio 2013, with the latest nuget packages.
YMMV. I'm not responsible for anything this code does on or to your system, including but not limited to fires, acts of God, and death.
Other than that, use however you want.
First, a new CrystalImageHandler. Obviously, change the namespace to whatever works for you:
using System;
using System.IO;
using System.Web;
using CrystalDecisions.Web;
namespace WebReporting.Code
{
/// <summary>
/// Rewrite of the CrystalImageHandler to work around a CR bug.
/// </summary>
public class CrystalImageHandler : IHttpHandler
{
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext Context)
{
string fileName = null;
try
{
fileName = string.Format("{0}{1}", ViewerGlobal.GetImageDirectory(), Context.Request.QueryString["dynamicimage"]);
var i = fileName.LastIndexOf('.');
var contentType = i >= 0 ? string.Format("image/{0}", fileName.Substring(i + 1)) : "image/gif";
Context.Response.Clear();
Context.Response.ContentType = contentType;
Context.Response.AppendHeader("Expires", DateTime.Today.AddYears(1).ToString("r"));
Context.Response.WriteFile(fileName);
Context.Response.Flush();
}
catch
{
Context.Response.Clear();
Context.Response.StatusCode = 404;
Context.Response.Flush();
Context.Response.End();
}
finally
{
if (fileName != null)
{
try
{
File.Delete(fileName);
}
catch
{
}
}
}
}
}
}
Here's the web.config entries you need. Again, change the names to match your project:
1) Comment out your entry which is similar to this (you don't need to replace it with anything, just comment it out):
<httpHandlers>
<!-- <add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />-->
</httpHandlers>
2) Comment out your entry which is simular to this, and add the 2 other entries:
<system.webServer>
<handlers>
<!-- <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,runtimeVersion4.0" />-->
<!-- I don't know if this works with other preConditions. I don't really understand preConditions to begin with, even after reading about them. -->
<add name="CrystalImageHandler_GET" verb="GET" path="CrystalImageHandler*" type="WebReporting.Code.CrystalImageHandler, WebReporting, Version=1.0.0.0, Culture=neutral" preCondition="integratedMode" />
</handlers>
</system.webServer>
This fixed the problem for me. Hope it works for you.