根据构建类型不同的 ASP.NET 4 页面内容

发布于 2024-09-05 05:45:58 字数 198 浏览 1 评论 0原文

在开发 ASP.NET MVC 2 网站时,我遇到了以下问题。在构建生产解决方案时,我需要在网站的母版页上呈现特殊脚本以进行 Google 分析,但对于调试和测试构建,不应呈现此脚本。我试图找到一种自动实现的方法,但没有成功找到解决方案。

我唯一的想法是创建一个批处理文件,在生产构建之前将必要的脚本附加到页面中,然后删除。但我想知道有没有更好的方案来解决这个问题?

While working on ASP.NET MVC 2 web site I faced to the following problem. I need to render speacial script on site's master page for Google analytics when building solution for production, but for debug and test builds this script should not be rendered. I've tried to find a way to make it automatically, but was not succeded in finding a solution.

The only idea I have is create a batch file that will append necessary script into the page before production build and remove after. But I wonder is there any better solution to solve this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独患者 2024-09-12 05:45:59

您应该能够使用预处理器指令

#if !DEBUG
               //render code here
#else
              //render something else
#endif

http:// /msdn.microsoft.com/en-us/library/ed8yd1ha(v=VS.100).aspx

You should be able to use preprocessor directives

#if !DEBUG
               //render code here
#else
              //render something else
#endif

http://msdn.microsoft.com/en-us/library/ed8yd1ha(v=VS.100).aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文