好的,所以我通过执行以下操作解决了它:
Public Overrides Sub RenderControl(writer As System.Web.UI.HtmlTextWriter)
If Me.RenderToFile Then
'Save it to a file first
Me.SaveImage(HttpContext.Current.Server.MapPath(RenderToFileLocation),
ChartImageFormat.Png)
'Return the image urn
writer.Write("<img src=""" & Url.Content(ConfigurationManager.AppSettings("ChartFilePath")) & "?c=" & Url.Content(RenderToFileLocation) & """ />")
Else
MyBase.RenderControl(writer)
End If
End Sub
然后从那里创建了一个简单的 .net MVC 处理程序,它返回文件并将其删除 Function Index(ByVal c As String) As ActionResult
Dim dir = Server.MapPath(ConfigurationManager.AppSettings("ChartFilePath"))
Dim filepath = System.IO.Path.Combine(dir, c)
Index = MyBase.File(filepath, "image/png")
'Delete the file
Try
IO.File.Delete(filepath)
Catch ex As Exception
End Try
End Function