Pointing to different includes depending on what server the file is on
So I'm working on a web site in ASP/VBScript. The files need to work on a development server and on a separate QA server at the same time. Unfortunately the dev server has an odd URL, so to make includes work on it breaks them on the QA server and vice versa. I tried using this code at the top of on of the pages:
<%
server = Request.ServerVariables("SERVER_NAME")
If (Lcase(Left(server, 3)) == "dev" Then
#include virtual ="/dev/Functions/DBConnection.asp"
#include virtual ="/dev/Functions/ValidationRoutines.asp"
Else
#include virtual ="/Functions/DBConnection.asp"
#include virtual ="/Functions/ValidationRoutines.asp"
End If
%>
I figured that this would work because the dev serve is dev.website.com and the virtual include path on that server needs to include the /dev/ directory. On all other servers (QA, Production) the /dev/ directory should be omitted as in the includes in the else block. When I try to use this code though I get an error and the page won't load开发者_如何学编程 (can't tell you what error because the only message I get is to contact the system administrator). The page does work if I only put the include appropriate to whichever server I am trying to run it on, so that is not the issue.
Any help with this would be greatly appreciated, Cody
I believe server
is a reserved word and I also don't think you can include files like that. Classic ASP also doesn't have ==
.
Update
The above still stands; I've removed the code sample since @Cheran S correctly points out that the includes would be processed before any code execution, meaning it would fail when trying to find the other files. You will have to use relative paths using #include file
instead of #include virtual
or, if unable to, move those include files to your site's root directory.
You can't make #include's within logic like that. ASP Does all of the #including before any logic is even considered. So with your code above, the server will try to include all of those files, and throw a compile error.
You could do
server.execute("somefile.asp")
, but that's just going to introduce more problems for you in the long run.
Instead of different paths though, why don't you create a virtual directory called 'dev' on the one machine? that way you can standardize the paths, and not have to worry about this issue at all?
精彩评论