Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Domain-Based Template Help
Old 01-31-2005, 01:56 PM Domain-Based Template Help
ppedersen's Avatar
Super Talker

Posts: 115
Location: Tampa Bay, FL - USA
Trades: 0
I have been programming in PHP for about five years now and for the first time having to do some ASP programming. I figured since I am proficient, "How hard can it be?" ...Apparently it can be very hard. I know way less ASP then I thought I did ;-)

Anyway, here's my problem. I have several domains. All the pages for the domain names sit in the same folder regardless of domain name. The content for all the domain names is the same. However , I want to use Request.ServerVariables("HTTP_HOST") to check which domain name is being accessed and then display a different template based on that domain name.

Here's the script I have written:

<% If Request.ServerVariables("HTTP_HOST") = "domain-1.com" Then %>
<!--#include virtual="/lib/inc/template_domain-1.asp" -->
<% ElseIf Request.ServerVariables("HTTP_HOST") = "domain-2.com" Then %>
<!--#include virtual="/lib/inc/template_domain-2.asp" -->
<% Else %>
<!--#include virtual="/lib/inc/template_default.asp" -->
<% End If %>

To me this makes sense. However what happens is, nomatter what the domain is it always includes template_default.asp. I added <%= Request.ServerVariables("HTTP_HOST") %> to the body of the test page to make sure that the domain was being returned correctly and it was. It does read the domain name correctly, but it still loads the incorrect template.

Any ideas?
__________________

Please login or register to view this content. Registration is FREE
(
Please login or register to view this content. Registration is FREE
)

Please login or register to view this content. Registration is FREE
's Website
ppedersen is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-31-2005, 02:20 PM
Anacrusis's Avatar
Defies a Status

Posts: 2,099
Name: Adam
Location: Colchester CT
Trades: 0
Try using request.servervariables("SERVER_NAME") instead, you may get better results.
Anacrusis is offline
Reply With Quote
View Public Profile
 
Old 01-31-2005, 03:02 PM
ppedersen's Avatar
Super Talker

Posts: 115
Location: Tampa Bay, FL - USA
Trades: 0
Nope. Same results. It always outputs the correct server, but the wrong template.

Basically it knows what the server name is but won't obey my command to use a different include. It always uses the last include listed in the script. Even if I remove the last "Else" statement (lines 5 & 6) so that there is only one "If" statement and one "ElseIf" statement (two choices), it always uses the last include in the script regardless of server name.

Any other thoughts??
__________________

Please login or register to view this content. Registration is FREE
(
Please login or register to view this content. Registration is FREE
)

Please login or register to view this content. Registration is FREE
's Website
ppedersen is offline
Reply With Quote
View Public Profile
 
Old 01-31-2005, 07:18 PM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
You can't use IF..Then statements with Includes. The include's get filled in first. You'd be better off doing a redirect.
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 01-31-2005, 07:33 PM
ppedersen's Avatar
Super Talker

Posts: 115
Location: Tampa Bay, FL - USA
Trades: 0
OK - I think I've got it worked out...

One of my goals was to keep the extra code in my 'content' (non-template) files to a minimum. I was able to get it down to three lines in my 'content' files and skip the "config.asp" file I was using. Basically I get the domain name then execute the two template files, a header file and a footer file, that include the domain name in the file name.

PHP Code:
# default.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% 
fttphost Replace(LCase(Request.ServerVariables("HTTP_HOST")), "www.""") %>
<% 
Server.Execute "/lib/inc/template_" fttphost "-head.asp" %>
<
p>Body</p>
<% 
Server.Execute "/lib/inc/template_" fttphost "-foot.asp" %> 
It seems to be working well, but I'm new to ASP and need to know if I'm setting myself up for failure further down the road.

Thanks so much.
__________________

Please login or register to view this content. Registration is FREE
(
Please login or register to view this content. Registration is FREE
)

Please login or register to view this content. Registration is FREE
's Website
ppedersen is offline
Reply With Quote
View Public Profile
 
Old 01-31-2005, 07:37 PM
Anacrusis's Avatar
Defies a Status

Posts: 2,099
Name: Adam
Location: Colchester CT
Trades: 0
Glad you got it working Paul, using server.execute should pose no forseeable failures. I've used that method in the past. It can be tricky to work with sometimes.

Quote:
You can't use IF..Then statements with Includes. The include's get filled in first. You'd be better off doing a redirect.
There is nothing wrong with using IF statements around includes, you are right about them all being included, but the IF statements should only allow part of it to actually be executed.
Anacrusis is offline
Reply With Quote
View Public Profile
 
Old 02-01-2005, 02:36 PM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
Yeah I probably should of used the word "shouldn't"...
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Reply     « Reply to Domain-Based Template Help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25176 seconds with 12 queries