Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to distinguish between Test and Production with Classic ASP

I have inherited a classic ASP application. There are various things that need tidying-up but I am forced to do things gradually (I can't do a wholesale change of every script).

There are places in the system with hard-coded urls. Some scripts have to be changed before promoting to live so that the test web root name is changed to the live web root name. I am looking at ways to avoid this (essentially working out the server programmatically).

It isn't difficult. A simple check on Request("SERVER_NAME") and this sort of thing:

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

This in an "everywhere-included" script will do the trick. Then just set up a global variable to hold the full "http(s)://server/app/" or a function to MakeUrlAbsolute() and off you go.

However, this smells a bit suspect to me. Wouldn't this be better stored at 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 hold of the SERVER_NAME so I'm reduced to having 2 different Global.asa files (one per environment).

Is this my only choice? Work it out on every request or hard-code in Application_OnStart? Perhaps using Session_OnStart would be a compromise. Or is there some clever trick to access information in Application_OnStart? Perhaps people go with the hard-coding because Global.asa doesn't change often.

like image 353
Fruitbat Avatar asked Nov 26 '13 14:11

Fruitbat


1 Answers

my method for ADO Connection looks like this.

'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)
like image 136
Sedat Kumcu Avatar answered Oct 21 '22 13:10

Sedat Kumcu