ASP: get the name of the current page
(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)
October 5th, 2004 at 4:16 pm
"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.
October 6th, 2004 at 12:51 am
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.
October 7th, 2004 at 5:56 am
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
October 7th, 2004 at 9:15 am
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".