Are there any differences between System.Web.HttpContext.Current.IsDebuggingEnabled
and System.Diagnostics.Debugger.IsAttached
?
If so, what are the exact differences besides the fact that one is only for web applications while the other works in all kind of projects?
Debugger. IsAttached is a runtime check, so the debugging code still gets included in the assembly, but only executes if a debugger is attached to the process.
Kernel-mode code can determine the status of kernel debugging by using the following variables and routines: The KD_DEBUGGER_ENABLED global kernel variable indicates whether kernel debugging is enabled. The KD_DEBUGGER_NOT_PRESENT global kernel variable indicates whether a kernel debugger is currently attached.
HttpContext.IsDebuggingEnabled
is about the compilation setting in the web.config. Debugger.IsAttached
defines if there is actually an active debugger listening to the information coming from the web server.
See the explanation at DotnetPerls regarding HttpContext.IsDebuggingEnabled
:
Debug mode is not the default. ... When you do not set debug="true" in Web.config, the site is compiled in Release mode.
Regarding your question why the first 'one is only for web applications': web applications have the ability to compile at run-time, while all other .NET products are pre-compiled. Because of this, you can define in the web.config if the build is done in Debug or Release mode. This is a ASP.NET only option, so the property is only available there.
As answer to your second question, why the first option is only for ASP.NET: There is also a way for a Windows application to check it's build status: by checking the DebuggableAttribute
as explained in How to check if an assembly was built using Debug or Release configuration?.
IsDebuggingEnabled
refers to "debug mode" which does not necessarily mean a debugger is actually attached. You can set ASP.NET websites into debug mode by setting <compilation debug="true">
in your web.config
file.
When a website is in debug mode, JIT optimizations are not applied to code contained within your view files (.aspx, .cshtml, etc) as well as any runtime-compiled code-behind files or the App_Code
directory. There are also other effects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With