ASP. NET debugging method

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.