问题描述
如何确定我的网站运行的模式?
在这种具体情况下,我在代码隐藏页面中有代码应该是一个方式在发布模式 - 这是有浏览器导航的人,另一种方式如果我处于来自VS2008的调试模式。 (这些是确定要使用哪个SQL连接字符串的东西,无论是否显示某些错误或警告消息等)
VS2008配置为通过IIS进行各种各样的原因(卡西尼不是一个选择)。
搜索所有帮助我找不到任何东西,但有一些方法来确定网站是如何开始。
提前感谢
我不是肯定你的意思如果您想知道应用程序当前是否正在调试,您可以检查 System.Diagnostics.Debugger.IsAttached
属性。如果您想知道应用程序是否在调试模式下编译,那么可以执行以下操作:
#if DEBUG
const bool DebugMode = true;
#else
const bool DebugMode = false;
#endif
此外,您可以使用ConditionalAttribute:
[System.Diagnostics.Conditional(DEBUG)]
public void ThisMethodWillOnlyExecuteInDebugMode()
{
}
/ b
我强烈建议重新考虑一下,尽管在我的经验中,有不同的发布和调试行为是一个很好的方式来引入错误到你的生产代码。
How can I determine what 'mode' my site is running under?
In this specific case, I have code in the code-behind pages that should act one way in 'release' mode - that is someone navigating there with a browser, and another way if I'm in debug mode coming from VS2008. (These are things like identifying which SQL connect string to use, whether or not to display certain error or warning messages, etc)
VS2008 is configured to go through IIS for a variety of reasons (Cassini is not an option).
Searching all through the help I can't find anything but there HAS to be a way to identify how the website was started.
Thanks in advance.
解决方案 I'm not sure what you mean. If you want to know if the application is currently being debugged, you can check the System.Diagnostics.Debugger.IsAttached
property. If you want to know if the application is compiled in debug mode, then you can do this:
#if DEBUG
const bool DebugMode = true;
#else
const bool DebugMode = false;
#endif
Also, you can use ConditionalAttribute:
[System.Diagnostics.Conditional("DEBUG")]
public void ThisMethodWillOnlyExecuteInDebugMode()
{
}
I strongly suggest reconsidering that though - in my experience, having different release and debug behaviour is an excellent way to introduce bugs to your production code.
这篇关于如何识别ASP.NET站点是否正在运行“正常”或在“调试”通过Visual Studio?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!