PeterJ
PeterJ

Reputation: 3789

Using custom constants within a VB / ASP.NET site

I'm adding a test site variant to an existing ASP.NET project written in VB and I'd like to make it apparent to users they are in the test site with a different banner and background etc. I've created a new test configuration and under Compile | Advanced Compile Options I've added TEST_MODE="1" as a custom constant. Then I attempt to use the following code in the ASPX file:

<%
#If TEST_MODE = "1" Then
    Response.WriteFile("header_test2.htm")
#Else
    Response.WriteFile("header.htm")
#End If
%>

The IDE shows the first statement grayed out and doing a rebuild and deploy it is still including header.htm. I wondered if anyone has ideas on why it doesn't work or can suggest an alternative way to include different files depending on the active configuration.

Upvotes: 1

Views: 10594

Answers (1)

BuddhiP
BuddhiP

Reputation: 6451

These Conditional compilation constants are saved to the project file of yours, and it's not deployed to your web site.

And when the website runs, ASP.NET compiler won't find that constant.

You need to set compiler options for the website using the web.config if you want this to work in the deployed pages.

Here is a nice article on this. Hope it will help you.

http://haacked.com/archive/2007/09/16/conditional-compilation-constants-and-asp.net.aspx

Upvotes: 2

Related Questions