One of the goals in writing an ASP application is to minimize the number of places you have to work with code. There are lots of mechanisms for doing this, such as server-side includes, which allow you to include the contents of a common file into another.
However, there are cases in which you can minimize the total number of ASP files in your site by consolidating your code into one place. On the new ASP Techniques site, for instance, I have one file that is intelligent enough to show all the content on the site. Here’s the code from the Sub Main routine that runs first on the page. It’s just a Select/Case statement that checks the action codes and then calls the right routine. Each routine gets the appropriate key values to show the content, as well as a reference to an MTS component managing database access.
Sub Main
Dim strAction ' As String
Dim lngSectionID ' As Long
Dim lngPageID ' As Long
Dim lngCategoryID ' As Long
Dim lngContentID ' As Long
Dim strCommonID ' As String
Dim objDB ' As NCSBackOffice.Database
strAction = Request(ACTION)
Set objDB = Server.CreateObject("NCSBackOffice.Database")
Select Case strAction
Case ACTION_RETR_COMMON
strCommonID = Request("cID")
RetrieveCommonContent objDB, strCommonID
Case ACTION_RETR_SECT
lngSectionID = Request("sID")
RetrieveSection objDB, lngSectionID
Case ACTION_RETR_CAT
lngCategoryID = Request("cID")
If Request("pID") = "" Then
lngPageID = 1
Else
lngPageID = Request("pID")
End If
RetrieveCategory objDB, lngCategoryID, lngPageID
Case ACTION_RETR_CONTENT
lngSectionID = Request("sID")
lngContentID = Request("cID")
RetrieveContent objDB, lngSectionID, lngContentID
End Select
Set objDB = Nothing
End Sub
It’s all a matter of organization to do something like this. It’s not hard...it just takes some planning to make it work. If you’re interested in this sort of development, watch the ASP Techniques site for some upcoming articles about this topic.