Tải bản đầy đủ - 0 (trang)
Part X: Debugging and Troubleshooting ASP.NET

Part X: Debugging and Troubleshooting ASP.NET

Tải bản đầy đủ - 0trang

Chapter27.DebuggingASP.NET

Applications

INTHISCHAPTER

TheBasicsofDebugging382

EnablingandConfiguringDebuggingforanASP.NET

Application383

DebuggingServer-SideCode385

ExaminingtheStateofanApplication388

DebuggingClient-SideScripts392

UsingtheErrorListtoLocateApplicationErrors393

Checkpoint395



TheBasicsofDebugging

Anydeveloperwilltellyouthatonethingiscertainwhenwriting

computercode:bugs.Ashardasyoutrytoavoidbugs,you're

goingtointroducethemanytimeyouwritecode.Thehuman

brainisnotwiredtoworkthewayacomputerworks,and

becauseofthedisparitybetweenhumansandthepurelogicof

thecomputer,we'llhavesoftwarebugsuntilcomputersstart

writingsoftware.Yourjobasadeveloperistoavoidbugswhere

possibleandtotrackdownbugsifyou'veintroducedtheminto

yourcode.

Therearegenerallytworeasonswhyyouwouldneedtodebug

anapplication.Thefirstreasonisthatanerrormessageis

displayedandyouneedtofindoutwhy.Thesekindsof

problemsareusuallytheeasiesttotrackdownbecauseyou've

gotanindicatorofwhereinyourcodesomethingwentwrong.

Thesecondreasonwhyyoumightneedtodebugyour

applicationiswhenthedatausedbyyourapplicationisnot



whatyouexpectittobe.Thesekindsofproblemsareoften

difficulttotroubleshootbecausethesymptomscanbesubtle

andthecodethat'scausingtheproblemisoftennotthecode

thatisexecutingwhentheproblemisnoticed.

Note

Debuggingyourcodealsoprovidespeaceofmindin

knowingthatyourcodeworksthewaythatyouexpect

itto.

Theprocessofdebugginginvolvesstoppingtheexecutionofan

applicationataparticularpointandinvestigatingthe

application'sstate.Anapplicationisdebuggedbyanapplication

calledadebuggerthat'sdesignedtopeekintoanapplication

whileit'srunning.Thedebuggerhasaccesstothememorythat

theapplicationisusingandcanthereforedeterminethevalue

oftheapplication'svariablesandsoon.

Thedebuggercanalsoidentifythenameofthefilecontaining

thesourcecodethatisexecuting,andthelineofcodeinthat

filethatisexecutingatthetimeoftheerror.Toidentifythe

nameofthefileandthelinethatisexecuting,thedebugger

mustloadaspecialfilecalledasymbolfile.

Note

Thesymbolfileiscreatedwhentheapplicationthat's

beingdebuggedisbuiltintoanexecutablefile.



Youmightfindallthatmarginallyinteresting,butinfact,agood

debuggerpreventsyoufromhavingtobotherwithhowit

works.VisualWebDeveloperisjustsuchadebugger.

Configurationisalmostalwaystroublefree,andthepowerful

debuggingtoolsavailabletoyoumakeitmucheasiertotrack

downproblemsinyourcode.



PartX:DebuggingandTroubleshooting

ASP.NET











27DebuggingASP.NETApplications

28HandlingErrorsinanASP.NET

Application

29ASP.NETTracingandOther

TroubleshootingTechniques



Chapter27.DebuggingASP.NET

Applications

INTHISCHAPTER

TheBasicsofDebugging382

EnablingandConfiguringDebuggingforanASP.NET

Application383

DebuggingServer-SideCode385

ExaminingtheStateofanApplication388

DebuggingClient-SideScripts392

UsingtheErrorListtoLocateApplicationErrors393

Checkpoint395



TheBasicsofDebugging

Anydeveloperwilltellyouthatonethingiscertainwhenwriting

computercode:bugs.Ashardasyoutrytoavoidbugs,you're

goingtointroducethemanytimeyouwritecode.Thehuman

brainisnotwiredtoworkthewayacomputerworks,and

becauseofthedisparitybetweenhumansandthepurelogicof

thecomputer,we'llhavesoftwarebugsuntilcomputersstart

writingsoftware.Yourjobasadeveloperistoavoidbugswhere

possibleandtotrackdownbugsifyou'veintroducedtheminto

yourcode.

Therearegenerallytworeasonswhyyouwouldneedtodebug

anapplication.Thefirstreasonisthatanerrormessageis

displayedandyouneedtofindoutwhy.Thesekindsof

problemsareusuallytheeasiesttotrackdownbecauseyou've

gotanindicatorofwhereinyourcodesomethingwentwrong.

Thesecondreasonwhyyoumightneedtodebugyour

applicationiswhenthedatausedbyyourapplicationisnot



whatyouexpectittobe.Thesekindsofproblemsareoften

difficulttotroubleshootbecausethesymptomscanbesubtle

andthecodethat'scausingtheproblemisoftennotthecode

thatisexecutingwhentheproblemisnoticed.

Note

Debuggingyourcodealsoprovidespeaceofmindin

knowingthatyourcodeworksthewaythatyouexpect

itto.

Theprocessofdebugginginvolvesstoppingtheexecutionofan

applicationataparticularpointandinvestigatingthe

application'sstate.Anapplicationisdebuggedbyanapplication

calledadebuggerthat'sdesignedtopeekintoanapplication

whileit'srunning.Thedebuggerhasaccesstothememorythat

theapplicationisusingandcanthereforedeterminethevalue

oftheapplication'svariablesandsoon.

Thedebuggercanalsoidentifythenameofthefilecontaining

thesourcecodethatisexecuting,andthelineofcodeinthat

filethatisexecutingatthetimeoftheerror.Toidentifythe

nameofthefileandthelinethatisexecuting,thedebugger

mustloadaspecialfilecalledasymbolfile.

Note

Thesymbolfileiscreatedwhentheapplicationthat's

beingdebuggedisbuiltintoanexecutablefile.



Youmightfindallthatmarginallyinteresting,butinfact,agood

debuggerpreventsyoufromhavingtobotherwithhowit

works.VisualWebDeveloperisjustsuchadebugger.

Configurationisalmostalwaystroublefree,andthepowerful

debuggingtoolsavailabletoyoumakeitmucheasiertotrack

downproblemsinyourcode.



PartX:DebuggingandTroubleshooting

ASP.NET











27DebuggingASP.NETApplications

28HandlingErrorsinanASP.NET

Application

29ASP.NETTracingandOther

TroubleshootingTechniques



Chapter27.DebuggingASP.NET

Applications

INTHISCHAPTER

TheBasicsofDebugging382

EnablingandConfiguringDebuggingforanASP.NET

Application383

DebuggingServer-SideCode385

ExaminingtheStateofanApplication388

DebuggingClient-SideScripts392

UsingtheErrorListtoLocateApplicationErrors393

Checkpoint395



TheBasicsofDebugging

Anydeveloperwilltellyouthatonethingiscertainwhenwriting

computercode:bugs.Ashardasyoutrytoavoidbugs,you're

goingtointroducethemanytimeyouwritecode.Thehuman

brainisnotwiredtoworkthewayacomputerworks,and

becauseofthedisparitybetweenhumansandthepurelogicof

thecomputer,we'llhavesoftwarebugsuntilcomputersstart

writingsoftware.Yourjobasadeveloperistoavoidbugswhere

possibleandtotrackdownbugsifyou'veintroducedtheminto

yourcode.

Therearegenerallytworeasonswhyyouwouldneedtodebug

anapplication.Thefirstreasonisthatanerrormessageis

displayedandyouneedtofindoutwhy.Thesekindsof

problemsareusuallytheeasiesttotrackdownbecauseyou've

gotanindicatorofwhereinyourcodesomethingwentwrong.

Thesecondreasonwhyyoumightneedtodebugyour

applicationiswhenthedatausedbyyourapplicationisnot



whatyouexpectittobe.Thesekindsofproblemsareoften

difficulttotroubleshootbecausethesymptomscanbesubtle

andthecodethat'scausingtheproblemisoftennotthecode

thatisexecutingwhentheproblemisnoticed.

Note

Debuggingyourcodealsoprovidespeaceofmindin

knowingthatyourcodeworksthewaythatyouexpect

itto.

Theprocessofdebugginginvolvesstoppingtheexecutionofan

applicationataparticularpointandinvestigatingthe

application'sstate.Anapplicationisdebuggedbyanapplication

calledadebuggerthat'sdesignedtopeekintoanapplication

whileit'srunning.Thedebuggerhasaccesstothememorythat

theapplicationisusingandcanthereforedeterminethevalue

oftheapplication'svariablesandsoon.

Thedebuggercanalsoidentifythenameofthefilecontaining

thesourcecodethatisexecuting,andthelineofcodeinthat

filethatisexecutingatthetimeoftheerror.Toidentifythe

nameofthefileandthelinethatisexecuting,thedebugger

mustloadaspecialfilecalledasymbolfile.

Note

Thesymbolfileiscreatedwhentheapplicationthat's

beingdebuggedisbuiltintoanexecutablefile.



Youmightfindallthatmarginallyinteresting,butinfact,agood

debuggerpreventsyoufromhavingtobotherwithhowit

works.VisualWebDeveloperisjustsuchadebugger.

Configurationisalmostalwaystroublefree,andthepowerful

debuggingtoolsavailabletoyoumakeitmucheasiertotrack

downproblemsinyourcode.



EnablingandConfiguringDebuggingfor

anASP.NETApplication

TodebuganASP.NETapplicationinVisualWebDeveloper,you

havetoenabletheprojectfordebugging.Aftertheprojectis

enabledfordebugging,VisualWebDevelopercandebugit

accordingtotheconfigurationoptionsyou'veconfiguredforthe

project.



EnablingDebugging

Youenabledebuggingbyusingtheelementin

theweb.configfileintherootofyourapplication,andit's

disabledbydefault.Toenabledebugging,thefollowingline

needstobeaddedtotheweb.configfile:



Formoreinformationontheweb.configfile,see

"ASP.NETConfigurationFiles,"p.66.



Fortunately,youdon'thavetoknowhowtomanuallyenable

debuggingbecauseVisualWebDeveloperdoesitforyou

automaticallywhenyoufirstattempttodebugyourapplication.

Ifdebuggingisnotenabledwhenyoustartdebuggingyour

project,VisualWebDeveloperpromptsyouwiththedialog

showninFigure27.1.ClickYestoaddthe

elementtotheweb.configfileandenabledebugging.

Figure27.1.VisualWebDeveloperenablesdebuggingfor

youautomaticallywhenit'snotalreadyenabled.

[Viewfullsizeimage]



Tip

Fordetailsonwhyyoushouldalwaysdisabledebugging

beforemovingyourapplicationtotheliveserver,see

thesidebartitled"WhyYouShouldDisableDebugging

onaLiveSite."



YoualsoneedtomakesurethatASP.NETdebuggingisenabled

intheproject'sStartoptions.asdetailedinthenextsection.



WhyYouShouldDisableDebuggingonaLive

Site

YoumighthavenoticedthatthedialogshowninFigure

27.1warnsyouthatyoushouldalwaysdisable

debugginginaproductionapplication.Thereareseveral

reasonsforthat,butIthinktwoaremostimportant.

Firstofall,whenyouhavedebuggingenabled,Visual

WebDevelopercreatesoneDLLfileforeverypagein

yourapplication.TheseDLLfilesgetloadedintothe

memoryyourapplicationisusing,buttheyaren'tloaded

intoanyparticularlocationinmemory.Therefore,you

endupwithDLLfilessprinkledalloverthememory

spaceofyourapplication.

Thereasonwhyit'sbadtohavesomanyDLLsloaded

intomemoryinthisfashionisbecausetheyendup

decreasingtheamountofcontiguousmemoryavailable

toyourapplication.WhenanASP.NETapplicationruns,

theCommonLanguageRuntimeuseslargeblocks(upto

64megabytes)ofmemoryatatime,andallthis

memoryhastobecontiguous.IftheCommonLanguage

Runtimecan'tfindenoughcontiguousmemory,it

generatesanerrorintheformofan

OutOfMemoryException.Whenyourunyourapplication

withdebuggingdisabled,ASP.NETcreatesoneDLLfor

eachfolderinyourapplication,therebygreatlyreducing

thenumberofDLLfiles.

Thesecondmajorproblemwithrunninganapplication

indebugmodeisthatASP.NETpreventsrequestsfrom

timingoutwhenyouarerunningindebugmode.

Therefore,ifyouarerunningyourlivesiteindebug

mode,andauserrequestsapagethatcontactsa

databaseserverwhenthere'saproblemwiththe

databaseserver,thepagesitsandwaitsforaverylong



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Part X: Debugging and Troubleshooting ASP.NET

Tải bản đầy đủ ngay(0 tr)

×