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?

2 Answers 2

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

2
  • 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. Sep 4, 2014 at 21:56
  • @modiX: I updated the answer with a paragraph regarding your question. Sep 5, 2014 at 6: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.

1
  • 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. Sep 4, 2014 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.