Archive for the ‘ASP’ Category

Small ASP cheat sheet: getting current path (absolute URL), getting current script name.

September 21st, 2007 by Denis Golovtsov

Again I’d like to present small collection of solutions for my not favorite technology (not confuse it with ASP.NET which I respect).

When need get the default URL for the current sub folder (that can be used for example to present a link on this section of site in mail), can be used following code:

‘ getting absolute path for current sub folder

path = Left(Request.ServerVariables(URL),InstrRev(Request.ServerVariables(URL),“/”)

‘ if url need for a putting in email for example, so protocol and server name must e added

url = “http://” & Request.ServerVariables(“SERVER_NAME”) & path

Also can be helpful getting the name of current script (for a generating conditional dependent content for example), following peace of code will helpful:

file = Right(Request.ServerVariables(URL),Len(Request.ServerVariables(URL)) - Len(path))

In this case we use the path variable that need get before, and if we’d like to get file without calculate it, we should use following code:

file = Mid(Request.ServerVariables(URL),InstrRev(Request.ServerVariables(URL),“/”)+1)

ASP VBScript function to generate random password

August 17th, 2007 by Denis Golovtsov

Sometime I have to work with ASP projects. I don’t like ASP. At first because it’s old technology which almost doesn’t use in new projects now and this experience won’t very helpful. Any way I’d like to present here one simple function that might help someone.


‘       Generate random password

‘       @author Denis Golovtsov, http://goldenman.spb.ru/
       @param length integer - Tne length of generated password.
‘       @output string - Generated password.

Public Function NewPassword(length)

Dim range,password

range = “0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”
password = “”

Randomize

While length > 0
password = password & Mid(range, 1 + Int(Len(range) * Rnd), 1)
length = length - 1
Wend

NewPassword = password

End Function

I’m sure all are clear there and it doesn’t require additional comments.