Favorite Tips of IT Professionals (January 2000, IIS)
T-Shirts for Tipsters, January 2000
We were very impressed by the IIS tips submitted by IT Professionals for the T-Shirts for Tipsters contest. The IIS product support team combed through them all and selected the very best to share with you.
Congratulations to the January winners!
IIS/ASP tip: Nobody writes perfect code, even though we would all like to. And it is especially hard when you are not sitting right by the development server so you can't use the debugger. And one of my least favorite things to do is strip out/comment out all the debugging code - those innumerable "response.write"s that remain once the Web application is completed. So when I start development, I create an ASP page called something clever like "debug.asp" which contains a self-submitting form with a selection of input buttons that do various helpful things like list session variables, or turn a debug session variable flag on or off when evaulated after submitting.
In my ASP pages, there is an if statement for each response.write, which shows debugging information, so it is displayed only if the debug flag is set:
if session("debug") then response.write "referer='" & Request.ServerVariables("HTTP_REFERER") & "'<br>"
No more need to comment out those unneeded debug lines! It is also helpful once the Web application goes into production, if there is a need to see what is going on to fix any bugs missed in development.
Sample ASP code for setting session variable in debug.asp:
<% if Request("action") = "Debug On" then ' >>>>>>>>>>>>>> Debug On <<<<<<<<<<<<<<<< session("debug") = true response.write "<br><font color='red'><b>Debug flag is '" & session("debug") _ & "'</b></font><br>" elseif Request("action") = "Debug Off" then ' >>>>>>>>>>>>>> Debug Off <<<<<<<<<<<<<<<< session("debug") = false response.write "<br><font color='red'><b>Debug flag is '" & session("debug") _ & "'</b></font><br>" elseif Request("action") = "Abandon Session" then ' >>>>>>>>>>>>>> Abandon Session <<<<<<<<<<<<<<<< response.write "<br><font color='red'><b>Session abandoned." _ & " All session variables destroyed.</b></font><br>" session.abandon end if %> <html> <body> <form name="debug" action="debug.asp" method="post"> <input type="submit" name="action" value="Debug On"> <input type="submit" name="action" value="Debug Off"> </form> </body></html>
Debugging ASP Pages:
Debugging is a pain with ASP - especially if you are developing for a client which has their own server and is not setup for debugging.
I use the following technique:
When I want to debug a page I add "&Debug=1" to the URL.
In my ASP page at the top I put:
<% 'Set the Request Object value to a local variable 'for reduced overhead and cleaner code below If Request("Debug") = "1" Then Debug = True End if %> <% SQL = "Select * from tblAuthors where AuthID = " & AuthID If Debug Then Response.Write SQL End if rs.Source = SQL rs.Open %>