Crystal report not showing images : CrytalImageHandler not found - c#

I believe I have come across what I consider my most difficult task to do using crystal reports.
Problem
I am attempting to show to images on my report, one a varbinary stored in the database, and the second, a logo added from my desktop.The problem I am being faced with is, CrystalImageHandler not found and nothing I have tried works.
And the following errors are thrown
http://localhost:1979/ASP/CrystalImageHandler.aspx?dynamicimage=cr_tmp_image_9b453c74-dbe2-4f03-832e-b1bd43e6ec43.png 404 (Not Found)
http://localhost:1979/ASP/CrystalImageHandler.aspx?dynamicimage=cr_tmp_image_0bf1fda9-3e87-446d-94a4-aaad9aa7e53d.png 404 (Not Found)
What I have tried
I have attempted to ignore the routes. However, if I try to navigate to the image by removing the 'ASP' path where my aspx is, it still doesn't work. However, this is my RouteConfig.cs where the 'ASP' doesn't seem to be ignored
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
routes.IgnoreRoute("{*allaspx}", new { allaspx = #".*(CrystalImageHandler).*" });
routes.IgnoreRoute("ASP/{resource}.aspx/{*pathInfo}");
routes.IgnoreRoute("ASP/{resource}.aspx/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
I have also attempted to add it to the handler tag in the web.config file.
I have tried adding
<httpHandlers>
<add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web,Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
</httpHandlers>
to the main web.config however, on launching my application I get the error An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode. it then says I can ignore the error If you are certain that it is OK to ignore this error, it can be disabled by setting system.webServer/validation#validateIntegratedModeConfiguration to false. But setting that to false does not work.
I place it in the second web.config file(the one in views folder., but that does not fix the issue of no picture being displayed.
I would greatly appreciate it if I am offered assistance or a bit of guidance to solve this issue. Cause it seems odd that something so simple could be this challenging.

I also faced this issue regarding loading images on crystal report in mvc but able to solve this issue by following these steps.
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"/>
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 resolve this tell ASP.NET MVC routing engine to ignore requests for this resource. To do so, open up your routing configuration code (RouteConfig.cs).
There should already be an ignore for .axd resources. Add the following ignore rule:
routes.IgnoreRoute("{*allaspx}", new { allaspx = #".*(CrystalImageHandler).*" });
Source

I faced a similar issue. I found success in altering the path within the code shown below from Web.config. I replaced CrystalImageHandler.aspx with CrystalImageHandler*. This seems to have resolved my issue. I don't really understand why to be honest. I came someone's post online who suggested that he could'nt find the CrsytalImageHandler.aspx page and decided to point only to CrystalImageHandler. I thought this might be worth a try for some.
I was using VS2015, .Net 4.5, C#
<httpHandlers>
<add verb="GET" path="CrystalImageHandler*" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
</httpHandlers>
<handlers>
<add name="CrystalImageHandler.aspx_GET" verb="GET" path="CrystalImageHandler*" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" preCondition="integratedMode"/>
</handlers>
Hope this helps,
Mark

Add to RegisterRoutes
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
then fix CrystalImageHandler in Web.config
check web.config under <system.web> contains
(replace with crystal version)
<httpHandlers>
<add verb="GET" path="CrystalImageHandler*" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
</httpHandlers>
and under <system.webServer> contains
<handlers>
<add name="CrystalImageHandler.aspx_GET" verb="GET" path="CrystalImageHandler*" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" preCondition="integratedMode" />
</handlers>
Replace All
path="CrystalImageHandler.aspx"
with
path="CrystalImageHandler*"

After add necessary change in web.config. if still not work then you can try this
For ASP.NET MVC Project
in route config
add followoing line
routes.IgnoreRoute("Reports/Viewer/{resource}.aspx/{*pathInfo}");
you may need to change the path according to aspx page location

Related

Trying to call a WebMethod that resides on an .aspx page using jQuery

I’m trying to call a WebMethod that resides on an .aspx page using jQuery. In the development environment (localhost) works fine, but when I run it from the server it seems like the WebMethod is not called at all. The server environment tools I’m using are .Net 2.0 SP2, IIS7.5, and Visual Studio 2005.
The WebMethod that is being called creates and writes an .xml file. This file is then searched by another method that doesn’t find it since the WebMethod is not executed and the file was never created.
These are some of the things I’ve tried in order to fix the problem:
• Add a ScriptManager. I deleted it from the .aspx file since it didn’t fix the problem and read in a blog that a ScriptManager wasn’t needed in order to make the WebMethod call works.
• Set the property EnablePageMethods = true in the RadScriptManager. Currently it’s not set to true anymore since it didn’t fix the problem.
• Add a ScriptModule in the web.config file.
• Add the the Protocols in the web.config:
<system.web>
<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpPost"/>
<add name="HttpGet"/>
<add name="Documentation"/>
</protocols>
</webServices>
<system.web>
I deleted these from the Web.config file since they didn’t fix the problem and read in a blog that these tags were needed in environments running with .net 1.1 and IIS 5.0, IIS 5.1, IIS6.0.
• Assign write permissions to users and pools in order for them to be able to write to the folder. (IIS 7.5)
Am I missing something in the Web.config file? What could be causing the problem?
Here is the WebMethod:
[WebMethod]
public static string GetContinuityofCareDocument(string continuityofCareDocument, string indicator, string endOffile)
{
string _filePrefix = indicator;
string _fileNamexml = #"C:\TempFile" + _filePrefix + ".xml";
StreamWriter _txtFile = new StreamWriter(_fileNamexml, true);
_txtFile.Write(continuityofCareDocument);
_txtFile.Close();
return " Success";
}
Here is the where the WebMethod is being called from:
<script language="javascript" type="text/javascript">
function SendCcdtoServer(params,indicator,endOffile) {
jQuery.ajaxSetup({ async: true });
jQuery.ajax({
type: "POST",
url: '<%=ResolveUrl("WebServiceDisplayCCD.aspx")%>'+'/GetContinuityofCareDocument',
data: '{continuityofCareDocument: "'+params+'", indicator: "'+indicator+'", endOffile: "'+endOffile+'"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
error: function(response) {
alert("response + failure ");
}
});
}
function OnSuccess(response) {
alert("Success");
}
</script>
Here is the Web.config:
<configuration>
<configSections>
<sectionGroup name="Localization">
<section name="Localization" type="Localization.LocalizationConfigurationHandler, Localization,Version=1.0.0.0, Culture=neutral, PublicKeyToken=CA5930580A5E0032" />
</sectionGroup>
</configSections>
<system.web>
<pages enableViewStateMac="false" validateRequest="true" enableEventValidation="false" viewStateEncryptionMode="Never" smartNavigation="false" />
<httpModules>
<remove name="ScriptModule" />
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</httpModules>
<httpHandlers>
<add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
</httpHandlers>
<compilation debug="true">
<assemblies>
…
</assemblies>
</compilation>
<sessionState mode="SQLServer" sqlConnectionString="Data Source=###.###.###.#;User ID=XXXXX;password=XXXXXX" cookieless="false" timeout="60" />
<globalization enableClientBasedCulture="true" />
</system.web>
<location allowOverride="true" inheritInChildApplications="true">
<appSettings>
<add key="Authentication" value="Windows" />
</appSettings>
</location>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource"/>
</handlers>
</system.webServer>
</configuration>
When using chrome's developer tools I get a 500 error, which states "Invalid JSON" and contains the script of the whole page.
After searching for possible solutions to this error I get many blogs about how to solve an "Invalid JSON primitive" error, which doesn't seem to apply to the problem I'm dealing with.
What could be causing this?
Try to set a resolve var and look at it in debug:
var url = '<%=ResolveUrl("WebServiceDisplayCCD.aspx")%>'
I have spent a lot of time looking for the answer to this but could not find it on any site, even though it is a very simple answer:
It depends on parameter location in development mode and publish mode on internet.
In develop mode your URL is like this
http:// localhost:portnumber/yournamesite/pagesite/parameter
and location of your parameter sit on position 4 of url.
When you publish your site on internet on iis, your URL becomes
http://yoursite.com/pagesite/parameter
and location of your parameter is on position 3.

HttpHandler being overlooked in favor of route

I have built a custom HttpHandler that issues a status page whenever a specific resource is requested by the load balancer.
Some more background: It can't be a controller as I need to be able to share it with other assemblies and the company coding policy is not to allow controllers from other assemblies.
Also, I cannot use a delegating handler as I don't want to affect the pipeline by adding a global message handler.
So I have the following in the web.config:
<system.web>
...
<httpHandlers>
<!-- Status Page-->
<add verb="GET" path="*" type="Web.Api.Framework.StatusPageHandler, Web.Api.Framework" />
</httpHandlers>
...
</system.web>
<system.webServer>
...
<handlers>
<clear/>
<add name="StatusPageHandler" path="*" verb="GET" type="Web.Api.Framework.StatusPageHandler, Web.Api.Framework" />
</handlers>
...
</system.webServer>
When I try to access the handler (http://foo.bar/status) it fails with a 404. If I remove the resource mapping for the default controller (from global.asax) then it works. i.e. without the following statement in global.asax it works:
routes.MapRoute("Default", "{controller}", null, null);
I stumbled upon a url for which it does work: http://foo.bar/status/XXX, but that is hardly ideal - we don't want to have to extend the url in that "ugly" way.
How do I get it to work?
One way to get it to work. Change Web.Config like so.
<add name="StatusPageHandler" path="status" verb="GET"
type="Web.Api.Framework.StatusPageHandler, Web.Api.Framework" />
Add the line in Global.asax (RouteConfig.cs?) to ignore this route. Make sure you add this line before routes.MapRoute.
routes.IgnoreRoute("status");

ASP.NET MVC POST incorrectly returning HTTP 302

I've looked all over and can't find an answer to this. I have a simple test controller in ASP.NET MVC4 set up as follows:
public class TestController {
[HttpGet]
public ActionResult Index() {
MyModel model = new MyModel();
model.Debug += "GET Method";
return View(model);
}
[HttpPost]
public ActionResult Post(MyModel model) {
model.Debug += "POST Method";
return View("Index", model);
}
}
The Index view just has a form and a button that POSTs to /Test/Post which should just return HTTP 200 with the Index view. That works as expected on my laptop and on my server. But on the hosting provider I get the following when I perform the POST:
POST /Test/Post returns HTTP 302 Redirect to /Test/Post (What the heck?)
GET /Test/Post returns HTTP 404
How could this possibly happen? Any ideas for troubleshooting this problem?
The only difference that I know of between the environments is that I have .NET 4.5 installed and they have .NET 4.0 installed (and won't install 4.5 for some reason.) The projects target .NET 4 though, so don't think it would matter? Originally I had them targeting 4.5, but changed it after I learned that it isn't installed on the server.
Searching for ASP.NET POSTs returning 302 brings up a lot of questions about redirecting due to logins. But this controller isn't under any sort of restricted folder or [Authorize] attribute.
Update - web.config's
I've tried it with and without <authorization>, same results either way. Here is the system.web, in case this will help:
<system.web>
<customErrors mode="Off"/>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="30"/>
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="Database" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
</providers>
</membership>
<pages controlRenderingCompatibilityVersion="4.0">
<namespaces>
<add namespace="System.Web.Helpers"/>
<add namespace="System.Web.Mvc"/>
<add namespace="System.Web.Mvc.Ajax"/>
<add namespace="System.Web.Mvc.Html"/>
<add namespace="System.Web.Routing"/>
<add namespace="System.Web.WebPages"/>
<add namespace="Microsoft.Web.Mvc"/>
<add namespace="Tenido.Domain"/>
<add namespace="Tenido.Web.Mvc.Controllers"/>
</namespaces>
</pages>
<httpModules>
<add name="ImageResizingModule" type="ImageResizer.InterceptModule"/>
</httpModules>
</system.web>
After much back and forth, the hosting provider brought it to my attention that they don't support ASP.NET MVC 4, only up to 3. I'm not sure how or why they don't support the newer version, but that seems to be the root of the problem.
Needless to say, I moved to a host that supports the recent frameworks. Now the site works perfectly.
Use AllowAnonymous attribute in your controller Method
[AllowAnonymous]
[HttpGet]
public ActionResult Index() {
MyModel model = new MyModel();
model.Debug += "GET Method";
return View(model);
}
Hope it helps
For me, we had error redirect configured for custom errors via web.config
<system.web>
...
<customErrors mode="On" defaultRedirect="~/error/errorpage">
...
</customErrors>
It was doing a 302 after an internal error. Setting customErrors mode="Off" bubbled the error up all the way to the browser.
I had similliar problem.
What helped me was removing <authorization> tag from web.config.
It is not necessary for [Authorize] attributes and changed 302 to 404 code.
I had similar problem. After removing Authorization tag from web.config, it worked for me. Not sure about the reason.
If using cookie based authentication make sure the cookie being returned for .AspNet.ApplicationCookie (or whatever the name is) matches the domain of the site you're on
What sometimes happens to me is the cookie domain is incorrect for the site I'm on (due to my aging clumsy multi-hosted environment) - and then despite being issued a new auth cookie the browser can't send it back during the redirect (because it's a different domain) so it then redirects back to the auth page.

Register HttpHandler under a path/folder

Why cant i register a HttpModule under a directory?
<system.web>
<httpHandlers>
<add verb="*" path="/home/facebookredirect.axd" type="Facebook.Web.FacebookAppRedirectHttpHandler, Facebook.Web" />
</httpHandlers>
</system.web>
<handlers>
<add name="facebookredirect.axd" verb="*" path="/home/facebookredirect.axd" type="Facebook.Web.FacebookAppRedirectHttpHandler, Facebook.Web" />
</handlers>
when the request comes to /home/facebookredirect.axd i m getting a 404. why this is not working?
I want the facebookredirect.axd to work under /home/
Below is frm, global.asx
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
Essentially. home doesnt exist, there is a home controller. But i want to use this path.
path="/home/facebookredirect.axd"
should be:
path="home/facebookredirect.axd"
Also you need to exclude this url from your routes:
routes.IgnoreRoute("home/{resource}.axd");
It's probably because there is a generic .axd handler (i.e. *.axd) added before yours.
If you remove this before adding your handlers, then add it back in after your handler is added, it could resolve the problem (disclaimer: haven't tried it, just going on the evidence).
Try to add resourceType="Unspecified"
so it becames
<add name="facebookredirect.axd" verb="*" path="/home/facebookredirect.axd"
type="Facebook.Web.FacebookAppRedirectHttpHandler, Facebook.Web"
resourceType="Unspecified" />
At least, i have handlers working with folders with the same declaration.
Also folder "Home" should exists on server

Telerik Report Viewer messed up

Telerik Report messed up like this
Tried this fix that the article suggests but in vain..ie added "preCondition" attribute but we.config says preCondition="integratedMode" Attribute is not declared"..Where do I need to declare it and how!??
I added xmlns value like this in web.config after reading a forum:-
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
It still is giving this error:-
Unrecognized attribute 'preCondition'. Note that attribute names are case-sensitive.
[EDIT]
ok that fix is for IIS7..didn't notice..mine is IIS 5..so how do I fix the appearance of Telerik Report Viewer now??
Just in case, verify that you have the right "Version=xxxxx" on the web.config reference to the Telerik.ReportViewer.axd.
I've seen sometimes the report viewer messed up becasue the web.config was referencing an older version.
sample:
....
....
<add name="Telerik.ReportViewer.axd_*" path="Telerik.ReportViewer.axd" verb="*" type="Telerik.ReportViewer.WebForms.HttpHandler, Telerik.ReportViewer.WebForms, Version=5.1.11.928, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" preCondition="integratedMode,runtimeVersionv2.0" />
</handlers>
...
...
<add verb="*" path="Telerik.ReportViewer.axd" type="Telerik.ReportViewer.WebForms.HttpHandler, Telerik.ReportViewer.WebForms, Version=5.1.11.928, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" validate="true" />
</httpHandlers>

Categories