This topic is locked

Conditional display of debugging info

10/13/2017 8:36:57 AM
ASPRunner.NET Tips and tricks
Pete K author

You may already know that you can display SQL statements and/or all session variables in your pages for debugging purposes by adding code to the "After application initialized" event. But, like me, you may find yourself activating/deactivating that code during the development cycle, with each change requiring a re-compile. I have started adding the following code to every app I work on at the very start. It only displays the debugging information if you include specific querystrings in your request: debugSQL=true and/or debug=true. This way I can leave the code in without the debug info getting in the way when I don't need it. Remember to de-activate before production deploy.
Here's the code:


// Displays SQL statements if debugSQL=true

if (MVCFunctions.postvalue("debugSQL") == "true")

{

GlobalVars.dDebug = true;

}
// Displays all session vars if debug=true

if (MVCFunctions.postvalue("debug") == "true")

{

for (int i = 0; i < HttpContext.Current.Session.Count; i++)

{

var crntSession = HttpContext.Current.Session.Keys[i];

HttpContext.Current.Response.Write(string.Concat(crntSession, "=", HttpContext.Current.Session[crntSession]) + "

");

}

}


I hope this is helpful. Please share your tips as well!