vb.net 在 VB/ASP.NET 站点中使用自定义常量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13735877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:27:38  来源:igfitidea点击:

Using custom constants within a VB / ASP.NET site

asp.netvb.netvisual-studio

提问by PeterJ

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:

我正在向用 VB 编写的现有 ASP.NET 项目添加一个测试站点变体,我想让用户清楚他们在测试站点中使用不同的横幅和背景等。我创建了一个新测试配置和编译下| 高级编译选项我添加了 TEST_MODE="1" 作为自定义常量。然后我尝试在 ASPX 文件中使用以下代码:

<%
#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.

IDE 将第一条语句显示为灰色,并且进行了重建和部署,它仍然包含 header.htm。我想知道是否有人知道它为什么不起作用,或者可以建议一种替代方法来根据活动配置包含不同的文件。

回答by BuddhiP

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.

当网站运行时,ASP.NET 编译器将找不到该常量。

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

如果您希望它在部署的页面中工作,您需要使用 web.config 为网站设置编译器选项。

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

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