I recently learned the book. Net debugging, especially the Asp.net method for implementing Asp.net. The default is Asp.net.
Assert debugging is not available, so the assert class is customized and inherited from defaulttracelistener. The assert method of the debug class is associated
Fail method of listener, detailsCodeAs follows:
Using system;
Using system. Web;
Using system. diagnostics;
Using system. Windows. forms;
Public class assertclass: defaulttracelistener
{
Public override void fail (string message)
{
Fail (message, null );
}
Public override void fail (string message, string detailmessage)
{
Httprequest Req = httpcontext. Current. request;
If (req = NULL | Req. userhostname = Req. servervariables ["local_addr"])
{
Stacktrace T = new stacktrace ();
String display = message + "\ n" + detailmessage + "\ n" + "launch debugger? \ N "+ T. tostring ();
Dialogresult
R = MessageBox. Show (display, "assert
Failed ", messageboxbuttons. yesno, messageboxicon. error, messageboxdefaultbutton. button1,
Messageboxoptions. defaulttopics toponly );
If (r = dialogresult. Yes)
Debugger. Break ();
}
}
}
Add the following code to the application_onstart event processing of Global. asax. CS:
Debug. listeners. Clear ();
Debug. listeners. Add (New assertclass ());
In this way, you can use the Debug. Assert (...) statement freely on the Asp.net page. Remember that the assert method only applies to debugging versions.Program!