0

On a page (I've called Cashflow.aspx) I have an asp.net chart to plot out some data. It works wonderfully when debugging on my local machine. However, when I try to deploy the site to my staging server there is an error that I can't seem to track down. It fails and redirects back to my default.aspx page. If I comment out the chart and deploy again the rest of the page works just fine.

aspx Page:

<%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">


<div class="container-fluid">
    <div class="row">&nbsp;</div>
    <div class="panel panel-success">
        <div class="panel-heading">Cashflow</div>
        <div class="panel-body">
            <div class="row">
                <asp:Chart ID="Chart1" runat="server" Width="1400px" Height="500px">
                    <Series>
                        <asp:Series Name="As Bid Projected Cashflow" ChartType="Line" ChartArea="ChartArea1" BorderWidth="3" BorderColor="#86a44a"></asp:Series>
                        <asp:Series Name="Actual Cashflow" ChartType="Line" ChartArea="ChartArea1" BorderWidth="3" BorderColor="#da8137"></asp:Series>
                    </Series>
                    <ChartAreas>
                        <asp:ChartArea Name="ChartArea1" />
                    </ChartAreas>
                </asp:Chart>
            </div><div class="row">&nbsp;</div>

        </div>
    </div>
</div>

</asp:Content>

Code Behind:

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.Entity;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.WebControls;

namespace MySite
{
    public partial class Cashflow : System.Web.UI.Page
    {
    DataTable tbl;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            LoadData();
            decimal maxValue = 0;

            Chart1.DataSource = tbl;
            Chart1.Series["As Bid Projected Cashflow"].XValueMember = "Period";
            Chart1.Series["As Bid Projected Cashflow"].YValueMembers = "AsBidProjectedCashflow";
            Chart1.Series["Actual Cashflow"].XValueMember = "Period";
            Chart1.Series["Actual Cashflow"].YValueMembers = "ActualCashflow";
            Chart1.Series["Actual Cashflow"].Sort(PointSortOrder.Ascending);

            Chart1.ChartAreas[0].AxisX.LabelStyle.Angle = 45;
            Chart1.ChartAreas[0].AxisY.LabelStyle.Format = "C";
            Chart1.Legends.Add("As Bid Projected Cashflow");
            Chart1.Legends["As Bid Projected Cashflow"].Position.Auto = false;
            Chart1.Legends["As Bid Projected Cashflow"].Position = new ElementPosition(0, 0, 30, 15);
            Chart1.Legends["As Bid Projected Cashflow"].Docking = Docking.Right;
            Chart1.Legends["As Bid Projected Cashflow"].DockedToChartArea = "ChartArea1";
            Chart1.Legends["As Bid Projected Cashflow"].IsDockedInsideChartArea = false;
            Chart1.ChartAreas[0].Position.Auto = false;
            Chart1.ChartAreas[0].Position = new ElementPosition(0, 15, 105, 85);
            Chart1.DataBind();
        }
    }

    private void LoadData()
    {
        SqlConnection con = new SqlConnection();
        con.ConnectionString = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString;
        con.Open();
        SqlCommand cmd = new SqlCommand();
        SqlDataAdapter da = new SqlDataAdapter();
        tbl = new DataTable();
        cmd = new SqlCommand("GetCashflow", con);
        cmd.CommandType = CommandType.StoredProcedure;
        da.SelectCommand = cmd;
        da.Fill(tbl);
    }

    protected void btnRefreshCharts_Click(object sender, EventArgs e)
    {
        Response.Redirect("Cashflow.aspx?pnum=" + Request.QueryString["pnum"]);
    }
}
}

(Relevant) Web.config

<?xml version="1.0" encoding="utf-8"?>

<configuration>
  <configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <system.web>
    <httpHandlers>
      <add 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"  />
    </httpHandlers>
    <compilation debug="true" targetFramework="4.6">
      <buildProviders>
        <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
      </buildProviders>
      <assemblies>
        <add assembly="Microsoft.ReportViewer.WebForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91" />
        <add assembly="Microsoft.ReportViewer.Common, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91" />
        <add assembly="Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
      </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.6" requestValidationMode="2.0" maxRequestLength="262144000" executionTimeout="110" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Optimization" />
        <add namespace="Microsoft.AspNet.Identity" />
      </namespaces>
      <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>
  </system.web>
  <system.webServer>
    <!--<modules>
      <remove name="FormsAuthentication" />
    </modules>-->
    <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>
  <entityFramework>
    <defaultConnectionFactory  type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <appSettings>
    <add key="ChartImageHandler" value="storage=file;timeout=20;" />
  </appSettings>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
</configuration>

Network Monitor enter image description here

All relevant dlls are installed and up to date. Not really sure where to look next to track down the issue. Any pointers are greatly appreciated.

mac
  • 485
  • 1
  • 6
  • 29
  • 1
    Are you using Memory or a File to render the chart each time? I seem to recall there being an option to specify which and in the case of File, permissions may be an issue. –  Nov 09 '17 at 20:06
  • That was the issue. I was using a file. – mac Nov 10 '17 at 19:13

1 Answers1

0

The solution was to change this line in my web.config from:

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

to:

<add key="ChartImageHandler" value="storage=memory;deleteAfterServicing=true;" />
mac
  • 485
  • 1
  • 6
  • 29