asp.net:图表处理程序configuration中的临时目录无效

我得到这个错误Invalid temp directory in chart handler configuration [c:\TempImageFiles\]. 运行我的代码。

内部我得到No http handler was found for request type 'GET' error ,我通过引用没有http处理程序解决它

但是现在我正在得到上面的错误错误的细节

 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. 

这个错误的堆栈跟踪

 [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 

任何人都可以告诉我如何解决这个问题…我应该手动创build一个临时目录,或者我该怎么做…


嗨smarx,我检查它们..他们要求我改变

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

在networkingconfiguration文件…

但我没有在我的networkingconfiguration这一行

我只有这个定义图表

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

我现在应该怎么做….

您需要使用Web应用程序的文件夹层次结构中的临时目录。 在Windows Azure中,您无权访问c:\ TempImages,因此无法正常工作。

我创build了一个在Windows Azure中使用ASP.Net图表的快速示例: http : //code.msdn.microsoft.com/azurecharts

您仍然可以使用文件存储来获取临时图像:

如果您不想下载示例,请按以下步骤操作:

  1. 在您的解决scheme中,创build一个文件夹(例如,称为TempImages )。
  2. 添加一个文件( temp.txt ,或其他)到这个文件夹。 开发工具似乎不发布空目录。
  3. 将图表的图像位置设置为:

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

  4. 将以下内容添加到web.config中的 appSettings中:

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

  5. 确保以下内容在system.web / assemblies中

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

  6. 确保以下内容在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. 确保以下内容在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"/>

我上传到code.msdn.com的代码应该足以作为一个例子。

尝试将此密钥添加到您的web.config

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

而不是默认的一个:

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

如果改变下面的行

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

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

不起作用,则更改属性“storage = file;”的值 到“存储=内存” 。 它肯定会工作,因为现在你正在使用内存,而不是文件。

时间还在继续,人们仍然有build议。 我在迁移期间遇到了这个问题,所以我想我会加两分钱。

为什么把它存储在文件系统中,而不是只保存在内存中?

 <add key="ChartImageHandler" value="storage=memory;deleteAfterServicing=true;"/> 

如果文件系统是Azure中的问题,则不要使用它。

做以下事情

1)在web.config中添加或编辑以下键。

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

2)给IIS_User写入权限到这个目录,为此做以下事情:

 a) Go to Windows Explorer. b) Right click on c:\TempImageFiles Folder. c) click Properties. d) Select security tab , click Edit, click Add , Click Advanced, search for IIS_User. e) Add this IIS_User , give write permission to this user. f) Save and Close. 

现在,您已经设置了目录并向IIS授予了写入权限,以便将临时映像文件写入此文件夹。

它应该现在工作。

我有同样的问题,我的问题是我的提供商具有写权限的特殊文件夹,所以我将TempImagesFile文件夹更改为其默认文件夹,它的工作。

在我的情况下,具有写权限的文件夹被称为上传

web.config编辑:

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

希望这可以帮助其他;)

看看这个答案在Windows Azure论坛上: http : //social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/92238582-9445-4d15-a5a7-5f24fd4bf646/ 。

您可以通过使用BinaryStreaming来绕过临时图像caching。
谷歌应该做的rest。
它在Linux上适用于我,它为Linuxpath抛出了一个InvalidDirectoryexception。

(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> 

代码隐藏:

 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(); } 

或者像这样创build一个ashx处理程序

 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 

只需在C盘中创build一个名称为“TempImageFiles”的文件夹即可。