During compile time I can do a check like
#if DEBUG
Log(\"something\");
#endif
But what would be the preferred to check if debug=\"f
There's another, non-programmatic external and empirical way to check if you've accidentally left the debug=true
attribute on system.web/compilation
on a Asp.Net website, i.e. to detect if you've left this configuration on in web.config:
By using a tool such as Fiddler, you can intercept a GET request to your web site, and then change this so that to issue a non-Standard DEBUG HTTP Verb to the site, along with an extra Command: stop-debug
Header.
Raw
tab (since DEBUG isn't a standard HTTP verb option)GET
to DEBUG
Command: stop-debug
Header (above the Cookies), but leave the rest of the Headers and Cookies in placeDEBUG
commandIf the Web site returns 200 and the content OK
, then you know you've left debug on. The web site will return 403 - Forbidden
if debug
is off.
If you've got your website building on a CI/CD build pipeline, best way to turn debug off is to add the following XDT in your Web.Release.config
(Turning debug off in Production is a common security audit requirement)