Chart image link broken in load balanced intranet.


SYMPTOM

The chart image links sometimes appear broken in a load balanced intranet environment.

CAUSE

In this scenario, there are 2 http requests - one for the page which generates the image and then the client (browser) makes another for the actual image.  In a load balanced environment the same server which handles the first request may not handle the second.  As a result, the image will only be on one server and if the second request is made to another server the requested image will not be present on that machine.

SOLUTION

To circumvent this problem you could wrap the chart class with a class to manage the pathing for different servers.

Note: This solution will only work if each server in the server farm is accessible through http://(MachineName)/

[C#]

public class ClusterChart: dotnetCHARTING.Chart
{

     private string imageURL = "";
     public string ImageURL
     {
          get { return imageURL ; }
          set { imageURL = value ; }
     }
    
     public ClusterChart()
     {
          Random R =new Random();
          string filename = "chart" + R.Next().ToString() + ".png";
          this.TempDirectory = "temp";
          this.FileName = filename;
          this.ImageURL = "http://" + Environment.MachineName.ToLower() + "/temp/" + filename;
     }

     /// <summary>
     /// Renders the chart as an image instead of as a dotnetCHART
     /// </summary>
     protected override void Render(System.Web.UI.HtmlTextWriter writer)
     {
          writer.Write("<img border=0 src=\"{0}\">", this.ImageURL);
     }
}

 

Note: The above can be enhanced to use image maps. See sample features/ImageMapText.aspx in the zip file for more information.

Credits: Special thanks to Eric Wood from Charles Schwab for helping develop and test this solution.


Posted Wednesday, September 22, 2004 by Support
https://dotnetcharting.com/kb/KnowledgebaseArticle10440.aspx