Click here to Skip to main content
12,550,111 members (38,934 online)
Click here to Skip to main content
Add your own
alternative version


9 bookmarked

Custom File Extensions in ASP .NET - The Easy and Manageable Way

, 30 May 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
Custom file extensions such as Default.sample can be created very easily without the need to configure IIS.


Custom file extensions in ASP .Net pages are very easy to create. Over the course of learning and keeping myself up to date on the numerous changes that Microsoft keeps on implementing to the .NET Framework, this is probably one the easiest techniques to implement. Nonetheless, it has also been a source of confusion for many, partly because of the reason that most tutorials on this topic deal with adding mappings in IIS. But, is there another way? May be you do not want to play around with IIS settings, or you just do not have IIS setup.

Using the code

This tutorial discusses a very simple technique to implement custom file extensions (such as default.sample, or default.ecubicle) in to your web application. A step by step solution is presented and then discussed.


a) Add a new class to your project by right clicking on the Add New Item Node of your Web App. Name the class

b) The class must implement IHTTPHANDLER interface. Therefore the definition of class should look like:

Public Class Class1 Implements IHttpHandler

c) Visual Studio would automatically fill the source with IsReusable property and ProcessRequest method.

Public ReadOnly Property IsReusable() As Boolean _
                          Implements System.Web.IHttpHandler.IsReusable
End Get
End Property

Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) _
                          Implements System.Web.IHttpHandler.ProcessRequest 
End Sub 

d) Add the following code to PrcessRequest


e) Add the following code in Get section of the IsReusable property

Return False 

f) In Web.Config file, find <httphandlers> section and add this code. Customextension is any extension that you wish to use.

<add verb="*" type="Class1" path="*.customextension"/> 

g) Now, create a default2.aspx. This default2.aspx is your main page and you can do whatever you want here.

h) In the end, add a blank web form named default.customextension and set this form as your web site's startup by going to WebSite -> Start Options and selecting this page. You would not be able to set this as the web site's startup page by right clicking on it because the extension of the file is not .ASPX. But, you can do this by going into Website -> Start Options and selecting default.customextension page.


What this code does is to implement HTTPHANDLER interface and intercept any requests to our custom extension defined in web.config file. Once, this is done, our ProcessRequest method calls server.transfer to redirect the request to another page. Server object’s transfer method is the key here because if we were to use Response.Redirect, the user’s could then see the file name (which in this case ends in .aspx) in the address bar of the browser.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Rafay Bin Ali
Software Developer (Senior) eCubicle Solutions
Canada Canada

You may also be interested in...


Comments and Discussions

QuestionUsage scenario? Pin
Chris Maunder31-May-08 12:20
adminChris Maunder31-May-08 12:20 
AnswerRe: Usage scenario? Pin
Rafay Bin Ali31-May-08 12:50
memberRafay Bin Ali31-May-08 12:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161021.1 | Last Updated 30 May 2008
Article Copyright 2008 by Rafay Bin Ali
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid