NCS Logo - Click for home page Northstar Developer Center
Platforms
All Platforms
.NET Framework (1.x - 4.x)
Active Server Pages
ASP.NET
C#
SQL Server
VB.NET
Visual Basic

Keywords
.NET Data Types
.NET E-mail
.NET Events
.NET Functions
.NET Object Programming
.NET System.Configuration
.NET System.Diagnostics
.NET System.IO
.NET System.Net
.NET System.Net.Sockets
Active Data Objects
ASP Architecture
ASP Black Belt
ASP Built-in Functions
ASP Built-in Objects
ASP Debugging
ASP Performance
ASP Security
ASP Syntax
ASP.NET Authentication
ASP.NET Controls
ASP.NET Data Access
ASP.NET Features
ASP.NET Master Pages
ASP.NET Page Events
ASP.NET Security
ASP.NET ViewState
Atom
Certifications
COM, DCOM, COM+
Data Access
E-Mail
Errors
Exporting Data
HTML Tips
IIS
Object-Oriented Programming
RSS
SQL
Uncategorized ASP Tips
VB API Programming
VB Forms
VB Syntax
XML

Book Support
Visual Basic 6 Bible
ASP Bible
ASP Weekend Crash Course
ASP.NET At Work
Creating Web Services

Getting the Page Name

Written by Eric Smith, Northstar Computer Systems LLC

I try to avoid hard-coding page names in my ASP code as much as I can. Files get merged and renamed, and suddenly you've got a bunch of code that doesn't match up any longer. On a recent project, I inherited some code that had this construct to let users report bugs:
<a href="bug.asp?pageid=<% = strThisPage %>">Report a Bug on this Page</A>
The strThisPage variable was being declared and set at the top of every page to be the name of the ASP file without pathnames or extensions. For instance, archive_top.asp would be shown as archive_top in the URL. To get rid of this redundant code, I made use of the SCRIPT_NAME variable in the ServerVariables collection. Here's how you would do it:
   Dim strPageID     ' As String
   strPageID = Request.ServerVariables("SCRIPT_NAME")
   strPageID = Left(strPageID, Instr(strPageID, ".") - 1)
   strPageID = Mid(strPageID, InstrRev(strPageID, "/") + 1)
   Response.Write "<a href=""bug.asp?pageid=" & strPageID & """>Report a Bug on this Page</a>"
This code was added to a function and included in a common footer file for the site.

Keywords: [ Uncategorized ASP Tips ]

Publication Date: 11/1/1999