The debugging method of the program has a lot to do with writing high-quality programs. Use it properly and get twice the result with half the effort. Next, I will share with you my understanding of ASP. NET debugging technology and hope you will give me more advice.
Conditional compilation:
Conditional compilation is one of the most important methods in. Net debugging. It can dynamically generate Running code based on the Compilation conditions.
Conditional compilation is a constant specified by/define when the code is generated. Combined with the # If constant .... # endif to determine whether to generate # if .... # endif code.
Conditional compilation constants can be specified in Project Properties> Configuration Properties> Generate> Conditional compilation constants, or in the command line. For a code file, you can also define it in the file header, for example, in the. CS file, # define debug, or # UNDEF debug to cancel. I personally think it is more flexible to specify the project attributes, because you can set different constants based on different configurations. Conditional compilation constant format: Debug; trace. Constants are not limited to debug and trace. You can specify any word.
After defining the condition compilation constant, we can use it in the program code. For example, to display some intermediate status information in the debug version, the release version does not need to be displayed. We can do this:
C #
/** // <Summary>
/// Initialization
/// </Summary>
Private void initialize ()
{
Try
{
Int x = 0;
Int I = 1/X;
}
Catch (exception E)
{
# If debug
Debug. listeners. Add (New textwritertracelistener (console. Out ));
// Debug. listeners. Add (New textwritertracelistener ("Debug result. log"); // write debugging information to the file.
Debug. autoflush = true;
Debug. writeline (E. Message );
Debug. Close ();
# Endif // debug
Response. Write ("initialization" + E. Message );
}
}
Conditional compilation options in web form code
To enable Conditional compilation in web form code, you need to set <% @ page Language = "C #" DEBUG = "true" %>
Debug in Web. config
In the web. the config file is <compilation defaultlanguage = "C #" DEBUG = "true"/>. This function is used to determine whether the program needs to load debugging symbols, if we want to run in IDE debugging mode, debug must be true, but to improve performance, we need to set debug to false during release.
Write so much for the moment.