21

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?

Martin Braun
  • 10,906
  • 9
  • 64
  • 105

2 Answers2

23

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?.

Community
  • 1
  • 1
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
  • No, no more questions. Btw, I did not ask "why the first option is only for ASP.NET". I was asking for more differences between those two options. Anyway, thanks for pointing out the `DebuggableAttribute` on windows applications. – Martin Braun Sep 04 '14 at 21:56
  • @modiX: I updated the answer with a paragraph regarding your question. – Patrick Hofman Sep 05 '14 at 06:42
7

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.

Dai
  • 141,631
  • 28
  • 261
  • 374
  • Thanks for additionally pointing out the differences of debug mode and without debug mode (about the JIT compiler). It accompanies the fact why a 2nd separate debug configuration makes sense, so it accompanies the fact we got two ways of checking for debug mode. – Martin Braun Sep 04 '14 at 21:58