Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

HttpHandler – A Certificate example

Posted by Paul on October 13, 2010


You are a developer at Grade Nineteen University. One of the recent requirments the management had is to create an online certificate.
So that the students that pass out should be able to view their Certificates online. This will definitely add some technological edge to the university.

The student will be given his own certification url as following:

On accessing the url, the following Certifcate image will be displayed for the student id: 100

(100.cert should be interpreted as “Show Certificate for Student Id as 100)


Easy Way of Implementation – But not the Best

The first thought of implementation would be to create jpg files for all the students and copy them into the cert folder of the website. This approach is feasible but following overheads are there:

· For 1000 students passed out each year it requires 50 MB disk space.

· While backing up database of site, we have to do backup of jpg files too which is tedious.

If we have to take a backup of the site, we have to copy the files separately and do the database backup separately.

Http Handlers for the Rescue – A better Approach

We can achieve the same behavior with little overheads – by avoiding files creation for certificates.

We can use the database records to dynamically create certificate based on the student url.

By default the ISAPI handlers, handle the .aspx url extensions. We have to create a new handler for .jpg file handling that would be redirected to our certificate creation code.


1. Create a new web application project

Create a new web application project and name it as Grade19University

2. Create a new class and implement the IHttpHandler interface

Create a new class named “CertHandler” and implement the IHttpHandler interface

Add the following code.

public class CertHandler : IHttpHandler


public bool IsReusable


get { return false; }


/// <summary>

/// Core Method

/// </summary>

/// <param name="context"></param>

public void ProcessRequest(HttpContext context)


StudentLibrary studentLibrary = new StudentLibrary();

Bitmap image = studentLibrary.GetCertificate


if (image != null)


context.Response.ContentType = "image/bmp";

image.Save(context.Response.OutputStream, ImageFormat.Bmp);



context.Response.Write("Invalid Student Id!");



// The StudentLibrary class contains all student id lookup and image generating code

// A Certificate template is stored in application resource file

3. Modify the config file

Open the web.config file and in the httpHandlers section add the new verb


<add verb="*" path="*.cert" validate="false" type="Grade19University.CertHandler, Grade19University"/>


4. Run the application and test the url

You can execute the application and see the certificates. The library contains 3 students information.





We can add more optimizations to the code like verifying the raw url, customizing the error messages etc.

The source code can be found in


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s