ASP.NET Chart not working on server

10,464

Solution 1

if you are on shared hosting c:\TempImageFiles\ folder doesn't exists on server, and if somehow you can add that folder, asp.net application doesn't have rights to write outside of its root folder

Store it to the session

<add key="ChartImageHandler" value="storage=session;timeout=20;" />

look at

http://blogs.msdn.com/b/deliant/archive/2008/12/02/managing-chart-generated-images-with-chart-image-handler.aspx?wa=wsignin1.0

Solution 2

I was struggling with this same issue on my Godaddy 4GH shared hosting plan and thought I would share my solution.

  1. Insert a chart control into Default.aspx

    The following code should pop up in your code behind file

    <%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
    
  2. Edit your web.config file

    I followed instructions on this blog and completely removed the httpHandlers node from my web.config file and overwrote the handlers node with the following code

    <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>
    
  3. Create a directory to store charts

    I created a new folder in the application root called Charts

  4. Change chart control settings

    Update the ImageStorageMode and ImageLocation properties like this

    <asp:Chart ID="Chart1" runat="server" ImageStorageMode="UseImageLocation" ImageLocation="~/Charts/ChartPic_#SEQ(300,3)">
        <series>
            <asp:Series Name="Series1">
            <Points>
            <asp:DataPoint AxisLabel="Greg" YValues="1" />
            </Points>
            </asp:Series>
        </series>
        <chartareas>
            <asp:ChartArea Name="ChartArea1">
            </asp:ChartArea>
        </chartareas>
    </asp:Chart>
    
  5. Publish to Godaddy

  6. Edit file permissions on the Charts folder on the published site

    • Log into your Hosting Control Center
    • Click on FTP File Manager under Content
    • Navigate to your application root
    • Check the checkbox next to your Charts folder
    • Click on Permissions on the menu
    • Uncheck Inherit
    • Check Write (leave Read checked)
    • Click OK

Every time you republish your application you will have to repeat step 6.

Solution 3

Guessing that the c:\TempImageFiles\ makes problems on your server

you can also try to set your storage mode to storage=memory istead of storage=file

check also this good documentation: http://www.4guysfromrolla.com/articles/081909-1.aspx

Share:
10,464
aiw
Author by

aiw

Here to learn.

Updated on June 04, 2022

Comments

  • aiw
    aiw almost 2 years

    I have been trying to make a web application and everything seems to be ok when I run it in my laptop but its just not working when I try uploading it into the server. I use a Godaddy windows server on .net 4. I tried tinkering with the web.config file but it doesnt seem to work.

    This is how my temp image save location in web.cofig looks life

      <add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" />
    

    Am I missing something? Please help.