scriptygoddess

05 Oct, 2004

ASP: get the name of the current page

Posted by: Jennifer In: Lessons learned

(Side note: I hate ASP. I love PHP. But sometimes mean people make me use ASP) ;o)

I needed to get the current page name and redirect to a different page if it was a certain name. (ie. 1.asp or 2.asp or… up to any two-digit + .asp)

First – to get the page name I used a script I found here:

Dim strURL, aryURL, pagename, objRegExp
strURL = Request.ServerVariables("SCRIPT_NAME")
aryURL = Split(strURL, "/", -1, 1)
pagename = aryURL(ubound(aryURL))

Then I check the page against a reg exp:

set objRegExp = new RegExp
objRegExp.Pattern = "^[0-9]{1,2}\.asp"
if objRegExp.Test(pagename) then
Response.Redirect("http://www.example.com/pageToRedirectTo.asp")
end if

(FYI – I'm trying to get a better grasp of regular expressions. I know they're useful, I just can't seem to wrap my head around them. We're still at the "it makes my eyes bleed" stage – which is also pretty much how I feel about ASP)

4 Responses to "ASP: get the name of the current page"

1 | Jenni the Jester

October 5th, 2004 at 4:16 pm

Avatar

"Side note: I hate ASP. I love PHP. But sometimes mean people make me use ASP"

I am right there with you. Ugh.
I myself am currently drowning in asp when all I want to do is convert it to php and be done with it. Grrr.

2 | Ryan

October 6th, 2004 at 12:51 am

Avatar

I'm trying to get a better grasp of regular expressions. I know they're useful, I just can't seem to wrap my head around them.

Same here. I spent hours yesterday trying to figure out a simple regular expression. When I figured it out I felt a great sense of accomplishment, but also great frustration at how easy the answer ended up being. That seems to be how we learn though. 😀

3 | Dave

October 7th, 2004 at 5:56 am

Avatar

Ditto – ASP is evil, PHP is sweetness and light. But there are bad people out there who make me use ASP sometimes too. They will be first to die when the revolution comes. Or something like that.

VBScript Regular Expressions? I have an article that might help … a guide to them intended to help people past the bleeding eyes stage:

VBScript Regular Expressions

4 | Dave

October 7th, 2004 at 9:15 am

Avatar

I forgot to say … your RegEx won't match 10, 20, 30, etc (anything ending in a zero). The following pattern should do the job:

objRegExp.Pattern = "^[1-9][0-9]?\.asp"

Reads: String starts with a digit from 1 to 9, and may be followed by a digit from 0 to 9, then ".asp".

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements