The best way to distinguish test and production from classic ASP

I have inherited a classic ASP application. There are different things that need to be tidied up, but I am forced to do something gradually (I cannot do a wholesale replacement for each script).

There are places in the system with hard-coded URLs. Some scenarios need to be modified before moving on to life so that the root name of the test website is changed to the real-time root name. I look at ways to avoid this (essentially programming the server programmatically).

This is not difficult. Simple check of request ("SERVER_NAME") and such things:

appName = Request.ServerVariables("SCRIPT_NAME")
i = InStr(2, appName, "/")   'keep initial "/"
 If i > 0 Then
    appName = Left(appName, i)
End If

This in the “included in all” script will do the trick. Then simply configure the global variable to hold the full "http (s): // server / app /" or the MakeUrlAbsolute () function from you too.

However, it smells a bit to me. Wouldn't that be better stored at the application level? This suggests setting it up in Global.asa, something like:

Sub Application_OnStart()
    Application("WebRoot") = ...
End Sub

But now I can’t get the name SERVER_NAME, so I reduce to the presence of two different Global.asa files (one for each environment).

Is this my only choice? Work on every request or hard code in Application_OnStart? Perhaps using Session_OnStart would be a compromise. Or is there some tricky trick to access information in Application_OnStart? Perhaps people come with hard coding, because Global.asa does not change often.

+4
1

ADO Connection .

'Servername for Application Root Drive
Select Case Left(Request.ServerVariables("PATH_TRANSLATED"), 1)
    Case "c" strSrvr = "80.212.207.211"   'my remote server ip
    Case Else strSrvr = "(local)"         'local Sql instance (my project on D: drive)
End Select

strConn = "Driver={SQL Server};Server="& strSrvr &";uid=DBUSER;pwd=MYPASS;database=MYDATABASE"

Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open(strConn)
+1

All Articles