英文文献与翻译.docx
《英文文献与翻译.docx》由会员分享,可在线阅读,更多相关《英文文献与翻译.docx(14页珍藏版)》请在冰豆网上搜索。
英文文献与翻译
ASP.NETTechnique
1.BuildingASP.NETPages
ASP.NETandthe.NETFramework
ASP.NETispartofMicrosoft'soverall.NETframework,whichcontainsavastsetofprogrammingclassesdesignedtosatisfyanyconceivableprogrammingneed.Inthefollowingtwosections,youlearnhowASP.NETfitswithinthe.NETframework,andyoulearnaboutthelanguagesyoucanuseinyourASP.NETpages.
The.NETFrameworkClassLibrary
ImaginethatyouareMicrosoft.Imaginethatyouhavetosupportmultipleprogramminglanguages—suchasVisualBasic,JScript,andC++.Agreatdealofthefunctionalityoftheseprogramminglanguagesoverlaps.Forexample,foreachlanguage,youwouldhavetoincludemethodsforaccessingthefilesystem,workingwithdatabases,andmanipulatingstrings.
Furthermore,theselanguagescontainsimilarprogrammingconstructs.Everylanguage,forexample,canrepresentloopsandconditionals.EventhoughthesyntaxofaconditionalwritteninVisualBasicdiffersfromthesyntaxofaconditionalwritteninC++,theprogrammingfunctionisthesame.
Finally,mostprogramminglanguageshavesimilarvariabledatatypes.Inmostlanguages,youhavesomemeansofrepresentingstringsandintegers,forexample.Themaximumandminimumsizeofanintegermightdependonthelanguage,butthebasicdatatypeisthesame.
Maintainingallthisfunctionalityformultiplelanguagesrequiresalotofwork.Whykeepreinventingthewheel?
Wouldn'titbeeasiertocreateallthisfunctionalityonceanduseitforeverylanguage?
The.NETFrameworkClassLibrarydoesexactlythat.Itconsistsofavastsetofclassesdesignedtosatisfyanyconceivableprogrammingneed.Forexample,the.NETframeworkcontainsclassesforhandlingdatabaseaccess,workingwiththefilesystem,manipulatingtext,andgeneratinggraphics.Inaddition,itcontainsmorespecializedclassesforperformingtaskssuchasworkingwithregularexpressionsandhandlingnetworkprotocols.
The.NETframework,furthermore,containsclassesthatrepresentallthebasicvariabledatatypessuchasstrings,integers,bytes,characters,andarrays.
Mostimportantly,forpurposesofthisbook,the.NETFrameworkClassLibrarycontainsclassesforbuildingASP.NETpages.Youneedtounderstand,however,thatyoucanaccessanyofthe.NETframeworkclasseswhenyouarebuildingyourASP.NETpages.
UnderstandingNamespaces
Asyoumightguess,the.NETframeworkishuge.Itcontainsthousandsofclasses(over3,400).Fortunately,theclassesarenotsimplyjumbledtogether.Theclassesofthe.NETframeworkareorganizedintoahierarchyofnamespaces.
ASPClassicNote
InpreviousversionsofActiveServerPages,youhadaccesstoonlyfivestandardclasses(theResponse,Request,Session,Application,andServerobjects).ASP.NET,incontrast,providesyouwithaccesstoover3,400classes!
Anamespaceisalogicalgroupingofclasses.Forexample,alltheclassesthatrelatetoworkingwiththefilesystemaregatheredtogetherintotheSystem.IOnamespace.
Thenamespacesareorganizedintoahierarchy(alogicaltree).AttherootofthetreeistheSystemnamespace.Thisnamespacecontainsalltheclassesforthebasedatatypes,suchasstringsandarrays.Italsocontainsclassesforworkingwithrandomnumbersanddatesandtimes.
Youcanuniquelyidentifyanyclassinthe.NETframeworkbyusingthefullnamespaceoftheclass.Forexample,touniquelyrefertotheclassthatrepresentsafilesystemfile(theFileclass),youwouldusethefollowing:
System.IO.File
System.IOreferstothenamespace,andFilereferstotheparticularclass.
NOTE
Youcanviewallthenamespacesofthestandardclassesinthe.NETFrameworkClassLibrarybyviewingtheReferenceDocumentationforthe.NETFramework.
StandardASP.NETNamespaces
TheclassescontainedinaselectnumberofnamespacesareavailableinyourASP.NETpagesbydefault.(Youmustexplicitlyimportothernamespaces.)ThesedefaultnamespacescontainclassesthatyouusemostofteninyourASP.NETapplications:
System—Containsallthebasedatatypesandotherusefulclassessuchasthoserelatedtogeneratingrandomnumbersandworkingwithdatesandtimes.
System.Collections—Containsclassesforworkingwithstandardcollectiontypessuchashashtables,andarraylists.
System.Collections.Specialized—Containsclassesthatrepresentspecializedcollectionssuchaslinkedlistsandstringcollections.
System.Configuration—Containsclassesforworkingwithconfigurationfiles(Web.configfiles).
System.Text—Containsclassesforencoding,decoding,andmanipulatingthecontentsofstrings.
System.Text.RegularExpressions—Containsclassesforperformingregularexpressionmatchandreplaceoperations.
System.Web—ContainsthebasicclassesforworkingwiththeWorldWideWeb,includingclassesforrepresentingbrowserrequestsandserverresponses.
System.Web.Caching—Containsclassesusedforcachingthecontentofpagesandclassesforperformingcustomcachingoperations.
System.Web.Security—ContainsclassesforimplementingauthenticationandauthorizationsuchasFormsandPassportauthentication.
System.Web.SessionState—Containsclassesforimplementingsessionstate.
System.Web.UI—ContainsthebasicclassesusedinbuildingtheuserinterfaceofASP.NETpages.
System.Web.UI.HTMLControls—ContainstheclassesfortheHTMLcontrols.
System.Web.UI.WebControls—ContainstheclassesfortheWebcontrols.
.NETFramework-CompatibleLanguages
Forpurposesofthisbook,youwillwritetheapplicationlogicforyourASP.NETpagesusingVisualBasicasyourprogramminglanguage.ItisthedefaultlanguageforASP.NETpages.AlthoughyousticktoVisualBasicinthisbook,youalsoneedtounderstandthatyoucancreateASP.NETpagesbyusinganylanguagethatsupportsthe.NETCommonLanguageRuntime.Outofthebox,thisincludesC#,JScript.NET,andtheManagedExtensionstoC++.
NOTE
TheCDincludedwiththisbookcontainsC#versionsofallthecodesamples.
DozensofotherlanguagescreatedbycompaniesotherthanMicrosofthavebeendevelopedtoworkwiththe.NETframework.SomeexamplesoftheseotherlanguagesincludePython,SmallTalk,Eiffel,andCOBOL.Thismeansthatyoucould,ifyoureallywantedto,writeASP.NETpagesusingCOBOL.
RegardlessofthelanguagethatyouusetodevelopyourASP.NETpages,youneedtounderstandthatASP.NETpagesarecompiledbeforetheyareexecuted.ThismeansthatASP.NETpagescanexecuteveryquickly.
ThefirsttimeyourequestanASP.NETpage,thepageiscompiledintoa.NETclass,andtheresultingclassfileissavedbeneathaspecialdirectoryonyourservernamedTemporaryASP.NETFiles.ForeachandeveryASP.NETpage,acorrespondingclassfileappearsintheTemporaryASP.NETFilesdirectory.WheneveryourequestthesameASP.NETpageinthefuture,thecorrespondingclassfileisexecuted.
WhenanASP.NETpageiscompiled,itisnotcompileddirectlyintomachinecode.Instead,itiscompiledintoanintermediate-levellanguagecalledMicrosoftIntermediateLanguage(MSIL).All.NET-compatiblelanguagesarecompiledintothisintermediatelanguage.
AnASP.NETpageisn'tcompiledintonativemachinecodeuntilitisactuallyrequestedbyabrowser.Atthatpoint,theclassfilecontainedintheTemporaryASP.NETFilesdirectoryiscompiledwiththe.NETframeworkJustinTime(JIT)compilerandexecuted.
Themagicalaspectofthiswholeprocessisthatithappensautomaticallyinthebackground.AllyouhavetodoiscreateatextfilewiththesourcecodeforyourASP.NETpage,andthe.NETframeworkhandlesallthehardworkofconvertingitintocompiledcodeforyou.
ASPCLASSICNOTE
WhataboutVBScript?
BeforeASP.NET,VBScriptwasthemostpopularlanguagefordevelopingActiveServerPages.
ASP.NETdoesnotsupportVBScript,andthisisgoodnews.VisualBasicisasupersetofVBScript,whichmeansthatVisualBasichasallthefunctionalityofVBScriptandmore.So,youhavearichersetoffunctionsandstatementswithVisualBasic.
Furthermore,unlikeVBScript,VisualBasicisacompiledlanguage.ThismeansthatifyouuseVisualBasictorewritethesamecodethatyouwrotewithVBScript,youcangetbetterperformance.
IfyouhaveworkedonlywithVBScriptandnotVisualBasicinthepast,don'tworry.SinceVBScriptissocloselyrelatedtoVisualBasic,you'llfinditeasytomakethetransitionbetweenthetwolanguages.
NOTE
MicrosoftincludesaninterestingtoolnamedtheILDisassembler(ILDASM)withthe.NETframework.YoucanusethistooltoviewthedisassembledcodeforanyoftheASP.NETclassesintheTemporaryASP.NETFilesdirectory.Itlistsallthemethodsandpropertiesoftheclassandenablesyoutoviewtheintermediate-levelcode.
ThistoolalsoworkswithalltheASP.NETcontrolsdiscussedinthischapter.Forexample,youcanusetheILDisassemblertoviewtheintermediate-levelcodefortheTextBoxcontrol(locatedinafilenamedSystem.Web.dll).
IntroducingASP.NETControls
ASP.NETcontrolsprovidethedynamicandinteractiveportionsoftheuserinterfaceforyourWebapplication.ThecontrolsrenderthecontentthattheusersofyourWebsiteactuallyseeandinteractwith.Forexample,youcanusecontrolstocreateHTMLformelements,interactivecalendars,androtatingbanneradvertisements.
ASP.NETcontrolscoexistpeacefullywithHTMLcontent.Typically,youcreatethestaticareasofyourWebpageswithnormalHTMLcontentandcreatethedynamicorinteractiveportionswithASP.NETcontrols.
ThebestwaytounderstandhowASP.NETcontrolsworkinanHTMLpageistolookatasimpleWebFormsPage.
AddingApplicationLogictoanASP.NETPage
ThesecondbuildingblockofanASP.NETpageistheapplicationlogic,whic