asp.net:Invalid temp directory in chart handler co

2019-01-21 10:46发布

I am getting this error Invalid temp directory in chart handler configuration [c:\TempImageFiles\]. While running my code.

Intially I was getting No http handler was found for request type ‘GET’ error which I solved it by referring no http handler

But now I am getting the above error The details of the error are

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.DirectoryNotFoundException: Invalid temp directory in chart handler configuration [c:\TempImageFiles\].

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

The stackTrace of this error

[DirectoryNotFoundException: Invalid temp directory in chart handler configuration [c:\TempImageFiles\].]
   System.Web.UI.DataVisualization.Charting.ChartHttpHandlerSettings.Inspect() +851
   System.Web.UI.DataVisualization.Charting.ChartHttpHandlerSettings.ParseParams(String parameters) +1759
   System.Web.UI.DataVisualization.Charting.ChartHttpHandlerSettings..ctor(String parameters) +619
   System.Web.UI.DataVisualization.Charting.ChartHttpHandler.InitializeParameters() +237
   System.Web.UI.DataVisualization.Charting.ChartHttpHandler.EnsureInitialized(Boolean hardCheck) +208
   System.Web.UI.DataVisualization.Charting.ChartHttpHandler.EnsureInstalled() +33
   System.Web.UI.DataVisualization.Charting.Chart.GetImageStorageMode() +57
   System.Web.UI.DataVisualization.Charting.Chart.Render(HtmlTextWriter writer) +257
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +144
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +583
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +91
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +410
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +118
   System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +489
   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +84
   System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +713
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +144
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +583
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +91
   System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +91
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +410
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +118
   System.Web.UI.Control.Render(HtmlTextWriter writer) +60
   System.Web.UI.Page.Render(HtmlTextWriter writer) +66
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +144
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +583
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +91
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +7761

Can anyone tell me how to solve this problem... Should i have to create a temporary directory manually or what should i do...


Hi smarx, I check it.. They asked me to change

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

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

in web config file...

But I don't have this line in my web config

I have only this for defining chart

<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" />

What should I do now....

10条回答
Evening l夕情丶
2楼-- · 2019-01-21 11:31

You need to use a temporary directory that is within the folder hierarchy of your web application. In Windows Azure, you don't have access to c:\TempImages, so that is not going to work.

I created a quick sample of ASP.Net Charts working in Windows Azure here: http://code.msdn.microsoft.com/azurecharts

You can still use file storage for the temporary images:

If you don't want to download the sample, here are the steps to get it working:

  1. In your Solution, create a folder (called TempImages, for example).
  2. Add a file (temp.txt, or whatever) to this folder. The dev tools don't seem to publish empty directories.
  3. Set the image location of your chart to:

    ImageLocation="~/TempImages/ChartPic_#SEQ(300,3)"

  4. Add the following to appSettings in your web.config :

    <add key="ChartImageHandler" value="Storage=file;Timeout=20;Url=~/tempImages/;"/>

  5. Make sure the following is in system.web/assemblies :

    <add assembly="System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

  6. Make sure the following is in system.web/httpHandlers :
    <add path="ChartImg.axd" verb="GET,HEAD" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>

  7. Make sure the following is in system.webServer/handlers
    <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

The code I uploaded to code.msdn.com should suffice as an example.

查看更多
手持菜刀,她持情操
4楼-- · 2019-01-21 11:31

Just create a folder with name 'TempImageFiles' in C drive.

查看更多
beautiful°
5楼-- · 2019-01-21 11:35

You can circumvent temporary image caching by using BinaryStreaming.
Google should do the rest.
It worked for me on Linux, where it threw an InvalidDirectory Exception for Linux paths.

(RenderType="BinaryStreaming")

<asp:Chart ID="ChartDIN277" runat="server" Width="500" Height="200" RenderType="BinaryStreaming">
        <Series>
             <asp:Series ChartArea="ChartArea1" ChartType="Pie" 
                Name="Area" 
                XValueMember="Label" 
                YValueMembers="Area" 
                IsVisibleInLegend="false"> 
                </asp:Series> 
        </Series>
        <ChartAreas>
            <asp:ChartArea Name="ChartArea1">
                <Area3DStyle Enable3D="True" LightStyle="Realistic" />
            </asp:ChartArea>
        </ChartAreas>
</asp:Chart>

Codebehind:

protected void Page_Load(object sender, EventArgs e)
        {
            FillChartFromDataBase();
        }



        public void FillChartFromDataBase()
        {
            System.Data.DataTable table = new System.Data.DataTable();
            table.Columns.Add("Area", typeof(double));
            table.Columns.Add("Label", typeof(string));

            System.Data.DataRow row = table.NewRow();
            row["Area"] = 791;
            row["Label"] = "HNF 1";
            table.Rows.Add(row);

            row = table.NewRow();
            row["Area"] = 978;
            row["Label"] = "HNF 2";
            table.Rows.Add(row);

            row = table.NewRow();
            row["Area"] = 1262;
            row["Label"] = "HNF 3";
            table.Rows.Add(row);

            row = table.NewRow();
            row["Area"] = 1650;
            row["Label"] = "HNF 4";
            table.Rows.Add(row);

            row = table.NewRow();
            row["Area"] = 2519;
            row["Label"] = "HNF 5";
            table.Rows.Add(row);

            row = table.NewRow();
            row["Area"] = 6071;
            row["Label"] = "HNF 6";
            table.Rows.Add(row);


            // Set chart custom palette
            ChartDIN277.Palette = System.Web.UI.DataVisualization.Charting.ChartColorPalette.None;

            //ChartDIN277.PaletteCustomColors = New System.Drawing.Color() {System.Drawing.Color.Red, System.Drawing.Color.Blue}
            ChartDIN277.PaletteCustomColors = COR.Design.ColorPalette.Generate(System.Drawing.Color.ForestGreen, table.Rows.Count - 1);

            // http://student.csdn.net/space.php?uid=383581&do=blog&id=32768
            //ChartDIN277.Palette = System.Web.UI.DataVisualization.Charting.ChartColorPalette.None; 
            //ChartDIN277.PaletteCustomColors = new Color[] { System.Drawing.Color.Red, System.Drawing.Color.Blue};
            //// Hide all series empty data point by making them transparent
            //Chart.Series[0].EmptyPointStyle.Color = Color.Transparent; 
            //// Set color for the whole series
            //Chart.Series[0].Color = Color.Green;

            //// Set color of a single data point
            //Chart.Series[0].Points[5].Color = Color.Red;

            this.ChartDIN277.DataSource = table;
            this.ChartDIN277.DataBind();
        }




or create an ashx handler, like this

Imports System.Web
Imports System.Web.Services

Public Class ChartCreator
    Implements System.Web.IHttpHandler

    Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

        context.Response.ContentType = "image/jpeg"

        Dim yValues As Double() = {10, 27.5, 7, 12, 45.5}
        Dim xNames As String() = {"Mike", "John", "William", "George", "Alex"}


        Dim mychart As System.Web.UI.DataVisualization.Charting.Chart
        mychart = New System.Web.UI.DataVisualization.Charting.Chart
        Dim mychartarea As New System.Web.UI.DataVisualization.Charting.ChartArea()
        mychartarea.Name = "ChartArea1"
        mychartarea.BackColor = Drawing.Color.Transparent

        mychart.ChartAreas.Add(mychartarea)

        Dim myseries As New System.Web.UI.DataVisualization.Charting.Series()
        myseries.ChartArea = mychartarea.Name
        myseries.ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Pie
        myseries.Name = "Series1"

        mychart.Series.Add(myseries)
        mychart.BackColor = Drawing.Color.Transparent

        mychart.Series(0).Points.DataBindXY(xNames, yValues)
        mychart.Series(0).Points.DataBindXY(xNames, yValues)


        ' http://msdn.microsoft.com/en-us/library/system.web.ui.datavisualization.charting.rendertype.aspx
        ' ImageTag, BinaryStreaming, ImageMap
        ' mychart.RenderType = System.Web.UI.DataVisualization.Charting.RenderType.BinaryStreaming

        mychart.ImageType = System.Web.UI.DataVisualization.Charting.ChartImageFormat.Png


        'mychart.SaveImage(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "mychart.png"))
        mychart.SaveImage(context.Response.OutputStream)


        'getResizedImage(context.Request.PhysicalPath,Width,Height);
        'context.Response.OutputStream
        context.Response.End()

    End Sub

    ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class
查看更多
登录 后发表回答