About the method of debugging in ASP.net (reproduced from itpeople), but I personally disagree with the third recruit, with V

Source: Internet
Author: User
Tags config variables
The use of the ASP's people to its debugging should be a profound memory. Find those in the entire piece of code.
Mistakes in the place, it is difficult to imagine. Now Microsoft has introduced the ASP's replacement product asp.net. For
Asp. NET's benefits, I think a lot of websites have introduced similar, but for ASP.net debugging
That's not a lot to say. So, I wrote this article with a little personal experience. Because, I
Also contact asp.net soon, errors and omissions are inevitable, but also please correct me. Okay, here we are.

First Recruit: Configure Config.web

Generally, when we write good web pages run wrong, ASP. NET will tell us on the page that the program has
Wrong, but what exactly is wrong, it is no hint. In order to allow ASP.net to further prompt us to make a mistake
of information. It is necessary for us to edit the configuration information in the Config.web.

There are probably a lot of people who just contacted ASP.net who don't know config.web this file. Well, I'll introduce you by the way. Config.web is a asp.net configuration file containing all the configuration information about asp.net. When a asp.net page is executed, it looks for the file in the same directory as the page, and if it is not found, go to the previous directory and go to the Wwwroot directory. If not, it calls the Config.web file (x is the system directory) in the X:\WINNT\Microsoft.NET\Framework\v1.0.2204 directory. Therefore, if you want to change the configuration of all the pages, you should change the Winnt directory of the Config.web. Also, by the way, when you open config.web, you'll find that this is an XML structure configuration file.

Well, that's a lot of introductions, back to our theme. Now, the first step you need to make is: Hit
Open or create a new Config.web file. We separate to say:
If it's new, you need to create a new document with a text editor, and then enter it in the
Statement of the face:
<configuration>
<customerrors mode= "Off" ></customerrors>
</configuration>

After the loss, choose Save As, enter the filename config.web, save it to the current page in the same folder. If you are modifying an existing Config.web file, you only need to open it with a text editor, and then enter it anywhere between <configuration> and </configuration>:
<customerrors mode= "Off" ></customerrors>.

Now you can look at the prompts for the error page.
The last time we talked about configuring Config.web files, let the error message give more hints. But Light has
What's the use of hints? "The most is to know where the wrong is, but I will not change it!" "Don't worry, don't
Hurry and see what we call this article, "Sanbang", of course, it is a hatchet game! On
The trick is not strong enough, we have the bottom of that, so don't worry ah, and listen to my slow way.

Second trick: Trace tracking

Those who have used the ASP should have used the following statements:
Response.Write XXX
Response.End

Although I do not like the ASP's programming method, but this kind of convenient debugging method is very good. Swap with
Asp. NET, I find that ASP.net provides a more powerful debugging method, which is what we're going to say now
The trace. The so-called trace function is to add some tags in front of the page, as to what is the mark? Hey, I can't tell you right away (bad, rotten eggs ...). Wow! )。 I mean, I want to introduce a little bit of basic knowledge first!

I do not know how much you know about ASP.net's page markings, for the convenience of the following explanations, I still
Summary of the introduction of it! Asp. NET page mark refers to the top of every asp.net page, with
A statement enclosed by <%@ and%>. Its function is to determine when processing asp.net files, the need for the system
To do some special setup. The specific syntax is as follows:
<%@ directive Attribute=value%>
Where: Directive is the page designator; attribute is the corresponding property of the identifier.
Note: Spaces are required between attributes, and no spaces between "=".
Asp. NET now contains the following 7 kinds of identities
@ Page,
@ Control,
@ Import,
@ registe,
@ Assembly,
@ OutputCache,
@ Webservice

The most we use is the @ Page mark, and now I'm going to talk about the trace feature that uses the @ page. (For the specific application of these seven marks, I will post them later.) Well, back to our subject. To use the Trace feature, you must add the top of the page: <%@ page trace= "true"%> the sentence. When you're done, you can see how the page works. Run the page. You'll find a lot of data in the bottom half of the page. Let's explain the meaning of these data:
Request Details: Data that is read to the browser through the request method;
Trace Information: Process information for event occurrence or program execution;
Control tree: The hierarchical relationship between controls and controls used in Web pages;
Cookies Collection: Cookie information used in Web pages;
Headers Collection: The table header information for the browser.
The data information for the Server variables:server variable.

With this huge pile of data, we're doing a lot of work, but we're happy, and Trace offers a more powerful feature, so keep looking.

In addition to having the ASP.net page display this heap of data, we can also use the variables that are used in the program
The value is displayed in real time in the trace Information section by invoking the Trace.Warn or Trace.Write two methods. Their usage is as follows:
Trace.Warn ("Description", Variables);
Trace.Write ("Description", Variables);

I think you will ask, what is the difference between these two? The answer is: functionally, these two are identical, but in the display, Trace.Warn will be shown in red font
The third trick is to find the wrong artifact debugger

To use good weapons, no preparation is not, so we have to do a little preparation exercise.
1.config.web: Remember the first recruit said? Right, or this file, open it, add this statement to the inside
<compilation debugmode= "true" ></compilation>
Description: Because of the default, ASP. NET will run the page in normal mode, so that we have to add this statement in order to allow it to compile the Web page in error-checking mode.

2. Start Error Checking tool DbgUrt.exe: This program is placed in the X:\Program files\microsoft.net\frameworksdk\guidebug directory, the file name is DbgUrt.exe

3. Activation Error checking function:
Running the DbgUrt.exe program
--〉 Select Menu Debug/processes
In the Processes dialog box that appears,--〉 shows system processes and show processes in all sessions
--〉 find Xspwp.exe at the bottom of the Available Processes list box (if not, run an. aspx page and press the Refresh key. )
--〉 Select the file, press the Attach key
--〉 Select Common Language Runtime in the dialog box that appears, and then press OK to return to the Processes dialog box
--〉 Press the Close key
--〉 Select File/open/file in the main menu of the program to open the file you want to detect.

The following official start Page debugging.
Using DbgUrt.exe to open the file to debug, we have to do the first thing is: set the broken
Point. Does it feel like debugging with other Windows applications (like what?) It's a model.
Same! The way to add a breakpoint is simple, decide where you want to add a breakpoint, and then move the cursor to
The line, press F9 or click the left mouse button at the front of the line, and a question mark appears in front of the sentence.
Mark, this is the breakpoint! We can certainly set multiple breakpoints, as long as you like. If you like to cancel a
Breakpoint, you can simply repeat the breakpoint setting on the line.

After you set the breakpoint, just use the browser to browse the page being debugged, when the program runs to the bit of the breakpoint
, it automatically pops up the DbgUrt.exe and stops at the breakpoint position just now. This is, we can
To check the value of the variable using the Command Window-immediate window.

When we want to continue executing the current page, we have several options:
1, press F5 Key, run to the next breakpoint, if there is no breakpoint, then run the page;
2, press F11 key, perform one step operation;
3, press F10 Key, is also a single step operation, but it will enter the subroutine (function) in the statement.

Of course, the function of DbgUrt.exe is certainly more powerful than I introduced. Write ASP.net program, have
Such a sharp weapon, really saved us a lot of time Ah! Why not yet




Related Article

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.