Connecting Tech Pros Worldwide Forums | Help | Site Map

Auto detect whether code is being executed on localhost [IIS] or ISP web server

Newbie
 
Join Date: Oct 2009
Location: United Kingdom
Posts: 3
#1: Oct 10 '09
My project involves a large number of ASP pages that reference an Access database. I am testing the system first via IIS before publishing it to the web server.

The connection string is specific to the database location i.e. C:/inetepub/.../*.mdb etc for IIS testing and //web/content/.../*.mdb etc for the web server. Therefore I have to edit all of the files before publishing, then edit them back to continue with local deevelopment. Aagh!!!

Is there a way to introduce a simple 'test' into my codee as to where the ASP is running?

I could then 'if...then...else...' etc and save loads of time.

Hope you can help.

jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#2: Oct 12 '09

re: Auto detect whether code is being executed on localhost [IIS] or ISP web server


easiest solution is to have the connection string on a separate file and include it on all the pages that use it with a server-side include. Then just use a different copy of that include file on the local versus the hosted site. Does that make sense? Do you need help coding that?

Jared
Newbie
 
Join Date: Oct 2009
Location: United Kingdom
Posts: 3
#3: Oct 12 '09

re: Auto detect whether code is being executed on localhost [IIS] or ISP web server


Thanks jhardman - great idea. I've also been advised to explore server.mappath as a way of detecting the host server.
I prefer the 'includes' solution because of its apparent simplicity; I've not used includes previously but I am aware of the concept so I'll give it a go.
Cheers,
Al.
Newbie
 
Join Date: Oct 2009
Location: United Kingdom
Posts: 3
#4: Oct 12 '09

re: Auto detect whether code is being executed on localhost [IIS] or ISP web server


I just had a go at <--!includes... etc without much success. I created a new ASP file that simply declares a variable named 'path' then assigned the appropriate filepath to it. Then I used s-s includes in the code of my main page and set the connection string value to 'path'.
I think I've understood the principal correctly haven't I? It's most likely a lack of experience ony part as I'm relatively new to this and have probably got some syntax wrong somewhere!
I'll have another go soon.
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#5: Oct 13 '09

re: Auto detect whether code is being executed on localhost [IIS] or ISP web server


Here is an example, a file called "LAdmin.asp" being used as an include file
Expand|Select|Wrap|Line Numbers
  1. <%
  2. ' FileName="Connection_ado_conn_string.htm"
  3. ' Type="ADO" 
  4. ' DesigntimeType="ADO"
  5. ' HTTP="false"
  6. ' Catalog=""
  7. ' Schema=""
  8. Dim MM_LAdmin_STRING
  9. MM_LAdmin_STRING = "Provider=SQLOLEDB.1;Password=myPwd;Persist Security Info=True;User ID=myUID;Initial Catalog=myDB;Data Source=.\SQLExpress"
  10. %>
  11.  
from the top of one of my ASP pages:
Expand|Select|Wrap|Line Numbers
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
  2. <!--#include file="../Connections/LAdmin.asp" -->
  3. <%
  4. if request("chkCurrent") <> "" then
  5.     Set oConn = Server.CreateObject("ADODB.connection")
  6.     oConn.Open MM_LAdmin_STRING
Hope this helps.

Jared
Reply

Tags
asp, detect, localhost, online