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