ComponentOne Chart for .NET (2.0) Search HelpCentral 

ASP Page-based Rendering Tutorials

The ASP Page-based tutorials show how you can replace the built-in HttpHandler with custom ASP pages, thereby gaining extra control over the chart rendering mechanism. This method allows you to customize, for example, the behavior of the client and server caches, and IIS logging.

Both tutorials use the following ASP page to replace the HttpHandler mechanism, and differ only in the way they store the chart data. The code below can handle both Session and Cache transfers. It performs the exact same functions as the built-in HttpHandler, and should be useful as a starting point for your custom pages.

·      Visual Basic

Imports System

Imports System.Web

Imports System.Web.SessionState

 

Namespace AspPageSample

    _

 Public Class StreamResponse

 Inherits System.Web.UI.Page

 

  Private Sub Page_Load(sender As Object, e As System.EventArgs)

   ' Determine how the image is transferred to this page

   Dim ses As String = Request("SessionID")   ' non null if session transfer

   Dim cac As String = Request("CacheID")     ' non null if cache transfer

   Dim del As String = Request("Delete")      ' non null if delete request

   Dim doDelete As Boolean = False

  

   ' Check the delete request status

   If Not (del Is Nothing) Then

    del = del.ToLower()

    doDelete = del = "t" Or del = "true"

   End If

  

   Dim image As Byte() = Nothing

   Dim imgtype As String = String.Empty

   Dim img As String = String.Empty

   Dim hsh As String = String.Empty

  

   If Not (ses Is Nothing) Then

    ' extract the image info from the session object

    img = ses + "_ImageBytes"

    hsh = ses + "_Hash"

   

    image = CType(Session(img), Byte())

    imgtype = CStr(Session(hsh))

   

    If doDelete Then

     Session.Remove(img)

     Session.Remove(hsh)

    End If

   Else

    If Not (cac Is Nothing) Then

     ' extract the image info from the Application cache

     img = cac + "_ImageBytes"

     hsh = cac + "_Hash"

    

     image = CType(Cache(img), Byte())

     imgtype = CStr(Cache(hsh))

    

     If doDelete Then

      Cache.Remove(img)

      Cache.Remove(hsh)

     End If

    End If

   End If

   If Not (image Is Nothing) And Not (imgtype Is Nothing) Then

    ' return the binary image to the client

    imgtype = "image/" + imgtype.Substring((imgtype.LastIndexOf("."c) + 1))

   

    Response.Clear()

    Response.Cache.SetExpires(DateTime.MinValue)  ' clear client cache

    Response.ContentType = imgtype

    Response.BinaryWrite(image)

    Response.Flush()

   End If

  End Sub

 End Class

End Namespace

·      C#

using System;

using System.Web;

using System.Web.SessionState;

namespace AspPageSample

{

  public class StreamResponse : System.Web.UI.Page

  {

    private void Page_Load(object sender,

                 System.EventArgs e)

    {

      // determine how the image is

      // transferred to this page

      string ses = Request["SessionID"];

 

      // non null if session transfer

      string cac = Request["CacheID"];

 

      // non null if cache transfer

      string del = Request["Delete"];

 

      // non null if delete request

      bool doDelete = false;

 

      // check the delete request status

      if(del != null)

      {

        del = del.ToLower();

        doDelete = (del == "t" || del == "true");

      }

 

      byte [] image = null;

      string imgtype = string.Empty;

      string img = string.Empty;

      string hsh = string.Empty;

 

      if (ses != null)

      {

        // get image info from Session object

        img = ses + "_ImageBytes";

        hsh = ses + "_Hash";

        image = (byte[])Session[img];

        imgtype = (string)Session[hsh];

 

        if(doDelete)

        {

          Session.Remove(img);

          Session.Remove(hsh);

        }

      }

      else if (cac != null)

      {

        // get image info from Application cache

        img = cac + "_ImageBytes";

        hsh = cac + "_Hash";

        image = (byte[])Cache[img];

        imgtype = (string)Cache[hsh];

 

        if (doDelete)

        {

          Cache.Remove(img);

          Cache.Remove(hsh);

        }

      }

 

      // return image to the client

      if (image != null && imgtype != null)

      {

        int iext = imgtype.LastIndexOf('.')+1;

        imgtype = "image/" +

          imgtype.Substring(iext);

        Response.Clear();

        Response.Cache.SetExpires(DateTime.MinValue);

 

        // clear client cache

        Response.ContentType = imgtype;

        Response.BinaryWrite(image);

        Response.Flush();

      }

    }

  }

}

·      Delphi

procedure StreamResponse.Page_Load(sender: System.Object; e: System.EventArgs);

var

  hsh: string;

  img: string;

  imgtype: string;

  image: array of System.Byte;

  doDelete: Boolean;

  del: string;

  cac: string;

  ses: string;

begin

  ses := Request['SessionID'];

  cac := Request['CacheID'];

  del := Request['Delete'];

  doDelete := False;

  if (del <> nil) then

  begin

    del := del.ToLower;

    doDelete := ((del = 't') or (del = 'true'));

  end;

  image := nil;

  imgtype := Empty;

  img := Empty;

  hsh := Empty;

  if (ses <> nil) then

  begin

    img := (ses + '_ImageBytes');

    hsh := (ses + '_Hash');

    image := (array of System.Byte(Session[img]));

    imgtype := (string(Session[hsh]));

    if doDelete then

    begin

      Session.Remove(img);

      Session.Remove(hsh);

    end;

  end

  else

    if (cac <> nil) then

    begin

      img := (cac + '_ImageBytes');

      hsh := (cac + '_Hash');

      image := (array of System.Byte(Cache[img]));

      imgtype := (string(Cache[hsh]));

      if doDelete then

      begin

        Cache.Remove(img);

        Cache.Remove(hsh);

      end;

    end;

  if ((image <> nil) and (imgtype <> nil)) then

  begin

    imgtype := ('image/' + imgtype.Substring((imgtype.LastIndexOf('.') + 1)));

    Response.Clear;

    Response.Cache.SetExpires(DateTime.MinValue);

    Response.ContentType := imgtype;

    Response.BinaryWrite(image);

    Response.Flush;

  end;

end;


Using an ASP Page-based Rendering Method with a Session-based Transfer Method

Using an ASP Page-based Rendering Method with a Cache-based Transfer Method


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.