ASP.NET 4.0 WebForms URL Rewrite breaks MS Chart - asp.net

I've added the new Chart control to my project and it works well. I've set the
<add key="ChartImageHandler" value="storage=memory;timeout=20;" />
<handlers>
<add name="ChartImg" verb="*" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
Everything is fine as long as I use the "/host/Poll.aspx" path in my browser. Things break when switching over to the rewritten URL "host/poll/". I am getting the "System.Web.HttpException was unhandled by user code
Message=Error executing child request for ChartImg.axd." exception.
Any ideas how to fix it? Thank you very much!

I cant actually try this at the moment but how about "~/ChartImg.axd"
Failing that try using image locations
<add key="ChartImageHandler" value="Storage=file; Timeout=20; Url=~/Temp/Charting/;"/>
Edit: And update your chart html
<asp:Chart ID="chrt1" runat="server" Width="550px" Height="400px"
SuppressExceptions="True" ImageStorageMode="UseImageLocation"
ImageLocation="~/Temp/Charting/ChartPic_#SEQ(1000,30)">
And make sure the directory you are writing to exists. I normally do this on app start in the global

in case you upgrade your website from .Net 3.0 to .Net 4.0 and using IIS 7 you must insert some line in your webconfig like here :
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<remove name="ChartImageHandler"/>
<add name="ChartImageHandler" preCondition="integratedMode" verb="*" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</handlers>
</system.webServer>

Related

ASP.net 4.0 Chart Control IIS6 Images not being displayed

Here is my problem, have a Web Application that is being hosted using a Web Farm and Load balancer. The application is running on Framework 4.0, Windows 2003 server and IIS6. Our local host environment is Windows 7 and IIS7.
We noticed intermittent exceptions "The image is not found"and noticed the Web.config was pointing at 3.5
So we made a change to the web.config to point at 4.0
<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
We are also using a network share to store the chart images which is set in appSettings
<add key="ChartImageHandler" value="storage=file;timeout=300;dir=\\server\webdata\charts\;deleteAfterServicing=false;"/>
after making the changes in the web.config the images would not display on the production server running IIS6 or my local environment running IIS7. So I made a change in all the webforms using the chart control and added ImageStorageMode="UseImageLocation".
After making that change the chart images displayed in IIS7 and IIS6 but in production IIS6 they were being placed in the webform directory and ignoring the handler location (Network Share). My local environment is working fine but I cannot get the production setting correct. All my web.config settings are below and any help would be greatly appreciated.
<appSettings>
<add key="ChartImageHandler" value="storage=file;timeout=300;dir=\\SERVER\webdata\charts\;deleteAfterServicing=false;"/>
</appSettings>
<system.web>
<httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
<compilation debug="true" defaultLanguage="vb" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
<!--IIS 7 Handler Section-->
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<remove name="ChartImageHandler"/>
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer>
Since you use load balancing on servers, it is maybe not finding the correct image location. Why don't you try to use a session to store the images?
<appSettings>
<add key="ChartImageHandler" value="storage=session;timeout=20;" />
</appSettings>
Reference this for more info. We were having the same issue on a web farm. It would be wise to add deleteAfterServicing set to true.

URL Routing does not work on Windows EC2 instance

Recently we created a Windows Instance on Amazon EC2 and deployed our application.
Everything is working fine except URL Routing. For this I have googled everything and tried all the possible options right from changing the web.config, making sure HTTP Redirection feature is on in IIS and many other things but nothing seems to work it simply gives me 404 page not found.
My final web.config is looking like this beside the other required data
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRoutingModule"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
<handlers>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a"/>
</handlers>
<directoryBrowse enabled="false"/>
</system.webServer>
Can I know what is that, which I am missing as I have tested out all the options and nothing is working.

ASP.NET Charting Control not working on production server

I have an application that relies heavily on charting and currently the charts will work in the ASP.Net Development Server, but when I try to publish out to my server (Win 2008 Server R2, IIS 7), the charts do not show up.
Using Firebug, I can see that the call to ChartImg.axd returns a 404, and all I get is a blank image holder in IE, or nothing in Firefox. I've searched for about 3 or 4 hours so far, and have tried just about everything recommended, but nothing seems to be working.
I would like to use memory/HttpImageHandler, instead of the ImageLocation configuration.
My Web.Config
<appSettings>
<!--<add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" />-->
<add key="ChartImageHandler" value="storage=memory;timeout=20;deleteAfterServicing=false" />
</appSettings>
<system.webServer>
<handlers>
<remove name="ChartImageHandler" />
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST"
path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer>
<system.web>
<httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
validate="false" />
</httpHandlers>
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting"
assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</controls>
</pages>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
<customErrors mode="Off"/>
</system.web>
Does anyone have any ideas where I'm going wrong to keep this from working on my server?
I found the answer to my problem, but I believe that my problem stemmed specifically from how my code runs.
Once I set privateImages=false under appSettings for my ChartImageHandler, my images came up with no problem, using ImageLocation with file storage or HttpHandler with memory storage.
I looked at the listing here and realized that my code has NONE of the following:
Authentication
SessionID
AnonymousID
so the implicit default setting of privateImages=true was keeping me from downloading my images. When I set privateImages=false I had no problems and the charts worked correctly. I set my application to use Windows Authentication, and set privateImages=true and my charts are now being generated with either the Image Location setting or the HttpHandler setting.
Hopefully this is helpful. I know I spent a long time digging around and got nowhere.
This configuration work for me. You need to use memory as storage.
< add key="ChartImageHandler" value="storage=memory;deleteAfterServicing=true;timeout=20;"/>
It seems like security/permission issue. Are you saving charts to local folder, then assign write permission for IIS user and/or network services users for that folder.
Install the Microsoft Chart Controls on your webserver or try this:
ASP.Net Chart Control On Shared Hosting Environment
Also check that the HttpHandler is registered in system.webServer in your web.config when running under IIS 7.
<controls>
<add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting"
assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</controls>
try this: change Version=4.0.0.0 to Version=3.5.0.0
try this it was resolved in case of web.config runtime error
<pre>
<add key="ChartImageHandler" value="storage=memory;timeout=20;deleteAfterServicing=true;Url=~\temp\"
/>

ASP.NET Chart: What's wrong with my web.config. I can't display a chart

I just created a web page having a barebone chart with a few data points to test. On localhost, the chart is displayed as expected with no problem. But when I deployed to my webhost I got a 500 - Internal Server Error
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
Here's the web.config uploaded by Visual Studio. Could you tell me what's missing or wrong in this web.config. The appSettings look suspicious with a dir in C:, but how do I change it? Thanks.
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" />
</appSettings>
<system.webServer>
<handlers>
<remove name="ChartImageHandler" />
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer>
<system.web>
<httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
validate="false" />
</httpHandlers>
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting"
assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</controls>
</pages>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
</system.web>
</configuration>
try this link
http://asifhuddani.wordpress.com/2010/10/07/chart-control-asp-net-4-0-and-iis-7-problem/
and then delete dir=c:\TempImageFiles\; from web.config
I had the same problem, namely a 500 server error adding in the same section. Two changes resolved the 500 serve error.
replaced "add path="ChartImg.axd" verb="GET,HEAD with add path="ChartImg.axd" verb="GET,HEAD,POST".
Added line after system.webServer tag:
[validation validateIntegratedModeConfiguration="false"/]
I had to replace < with [, otherwise the preview did not show the tag.
Problem is the temporary directory. It could be because:
The directory no exists,
The user has no permission to the directory,
You are pointing to the wrong directory, or
when you move your programs form a local PC to a server you are no longer pointing to a local file, you are pointing to a URL
Solutions:
If you are using a web server, the easy and lazy solution is create a directory named temp where the aspx is located. In the same directory and give the users permission to modify.
If you are using a local PC you can use memory instead of file. No use this in the web server because is to heave for many users, but use:
<add key="ChartImageHandler" value="Storage=memory;Timeout=20;"/>
If you are using a web server, the best option is use a url instead of a file like this:
<add key="ChartImageHandler" value="storage=file;timeout=20;url=~/temp" />
You can use ~ / . or http://…
To Add permission to the ISS user, could be your user pool, windows user or any user as you used before. If you use Windows authentication, then you should grant permission to the user named “Domain Users”. Some people add permission to the user everybody. This permission should include “Modify”

MSCharts "No http handler was found for request type 'GET'" error

I tried to install MSCharts on my Win2008 server.
It installed without problem.
Then I wrote
in config.
But when I'm trying to open page with charts it returned following error.
No http handler was found for request type 'GET'
Do you have any thougths about the problem?
This is what you need for ASP.NET 4.0 / IIS 7.5 on Windows 7:
Your web.config must contain the following:
<appSettings>
<add key="ChartImageHandler" value="storage=file;timeout=20;" />
</appSettings>
<compilation targetFramework="4.0">
<assemblies>
<add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
<system.webServer>
<handlers>
<add name="ChartImg" verb="*" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer>
You also need this at the top of your aspx page:
<%# Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
Hope this helps
Like Danil said, IIS7 requires that you put the handlers in
<system.webserver>
<handlers>
Add the two lines below after the last add-in handles
<add name="ChartImg" verb="*" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="ReportViewer" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler,Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
Solution was in web config. IIS7 required to write handlers inside system.webserver but not in the system.web. So I just move handler and add name attribute as it became required.
Don't know anything about MSCharts, but I'd say try changing the AppPool for the app to 'Classic .NET AppPool'.
Alternatively, you may need to modify your web.config to add the handler in there. See Rick Strahl's post here.

Resources