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

Posts Tagged ‘’

What is Host Header and how to configure it?

Posted by Paul on January 11, 2011


Host Header is a third piece of information to identify a web site.

Thus the web site can be identified by using the following:

    • IP Address
    • Port
    • Host Header

Host Headers was introduced in HTTP 1.1

Eg: is the host header

Configuration in IIS

We can configure host header in IIS using inetmgr application.

After configuration we need to publish the host header in the WINS (Windows Name Service) or DNS (Domain Name Service) depending on the site is an intranet or internet site.


Posted in ASP.NET, IIS | Tagged: , , | Leave a Comment »

For Beginners: In ASP.NET how to show a Javascript Alert message box?

Posted by Paul on December 2, 2010

I have seen frequently that beginners in ASP.NET try to use Windows Forms MessageBox and fails.

I would like to say that MessageBox class is meant for Windows Forms Application and not ASP.NET Web applications.

In ASP.NET applications, you have to:

Use either a page to show the message


Use javascript alert function to show the message (the example is given below)


Create a new web application using File > New Project > Web > ASP.NET Web Application


In the solution Explorer, right click on the Default.aspx and use View Code command.

Replace the Page_Load method code as below:

protected void Page_Load(object sender, EventArgs e)


    string message = "Test Message Box in ASP.NET";

    string script = "<script language=’javascript’>alert(‘" + message + "’);</script>";

    ClientScript.RegisterStartupScript(GetType(), "key", script);


Now you can execute the application.


On loading the page you will see the following message box (if not enable javascript in your browser)


Posted in C# | Tagged: , , | Leave a Comment »

Deploying ASP.NET application to Production Server using FTP

Posted by Paul on November 30, 2010

Visual Studio really makes it simple for deploying web applications.

In this article we are going to use FTP for deployment.


Hope you have a web application with multiple folders and dozens of file.  Selecting each item and uploading to the site is really tedious job.  We can simplify it by the following.


You should have the following:

  • FTP Server Name
  • Username and Password
  • Folder on server


Open the solution and right click on the web project and choose the option Publish.


You should see the following dialog window.


Click on the “…” button highlighted against the Target location item.

You will be prompted with the dialog box below.


Enter your Server name, Directory, Username and Password.

Uncheck the Anonymous Login checkbox.

After entering, cilck the Open button.  This will close the dialog box.

Now you can click Publish to do the deployment.

Posted in ASP.NET, IIS | Tagged: , , , | Leave a Comment »

ASP.NET–How to format currency based on user’s browser setting

Posted by Paul on November 11, 2010

Hello All.  In this example I am trying to show how to format currency based on user’s browser setting.

Our aim is to show them the formatted currency like:

Format Language
$1,000.00 United States
1,000.00د.إ.‏ Arabic
R$ 1.000,00 Portugese
1.000,00 TL Turkish

Step 1: Create the ASP.NET Application

Create a new web application and on the default page place a button and label.

On the button click you can add the following code.

protected void Button1_Click(object sender, EventArgs e)


    CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture(this.Request.UserLanguages[0]);


    double value = 1000;

    Label1.Text = value.ToString("C", cultureInfo.NumberFormat);


The code collects the user language from Request object and uses the ToString() method to format the value.

That finishes the coding part.. Now you have to see the things working.  For this you have to run the application and test it by changing the browser language.  I will guide you through it.

Step 2: Execute the application

You can execute the application and see the page opened in your browser.


Try clicking the button and you can see the number formatted in current language.

Step3: Change Browser Language

In this step we have to change the browser language.

If you are using Internet Explorer choose Internet Options screen.


Click the Languages button on the bottom and you can see the following screen.


Click the Add button to add a new language.  Select Arabic, move it up using the “Move up” button and click Ok.


Now you are ready to test the code in Arabic.

Click the “Change Format” button again and you can see the number format in Arabic.


Note: After changing the languages to back in browser you might need to restart it.

Posted in C# | Tagged: , , , | Leave a Comment »

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

Posted in ASP.NET | Tagged: , , | Leave a Comment »

How to generate a bitmap dynamically in ASP.NET?

Posted by Paul on October 12, 2010

There are two steps in this process

Step1: Create the bitmap dynamically

private Bitmap GetDynamicBitmap()


Bitmap bitmap = new Bitmap(100, 100);

      Graphics graphics = Graphics.FromImage(bitmap);

      graphics.DrawString("Dynamic Bitmap", new Font("Calibri", 14, FontStyle.Bold), Brushes.Black,

      new PointF(10, 10));


      return bitmap;


Step2: Set the http response to bitmap

Bitmap bitmap = GetDynamicBitmap();

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

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

Posted in C# | Tagged: , , | Leave a Comment »