外文翻译ASPNET C#版Word文件下载.docx
《外文翻译ASPNET C#版Word文件下载.docx》由会员分享,可在线阅读,更多相关《外文翻译ASPNET C#版Word文件下载.docx(6页珍藏版)》请在冰豆网上搜索。
ASP.NET2.0inC#
ASP(ActiveServerPages)isarelativelynewtechnologythat’salreadyleaptthroughseveralstagesofevolution.Itwasintroducedaboutsevenyearsagoasaneasywaytoadddynamiccontenttoordinarywebpages.Sincethen,it’sgrownintosomethingmuchmoreambitious:
aplatformforcreatingadvancedwebapplications,includinge-commerceshops,data-drivenportalsites,andjustaboutanythingelseyoucanfindontheInternet.ASP.NET2.0isthelatestversionofASP,anditrepresentsthemostdramaticchangeyet.WithASP.NET,developersnolongerneedtopastetogetherajumbleofHTMLandscriptcodeinordertoprogramtheWeb.Instead,youcancreatefull-scalewebapplicationsusingnothingbutcodeandadesigntoolsuchasVisualStudio2005.Thecostofallthisinnovationisthelearningcurve.Notonlydoyouneedtolearnhowtouseanadvanceddesigntool(VisualStudio)andatoolkitofobjects(the.NETFramework),youalsoneedtomasteraprogramminglanguagesuchasC#.TheInternetbeganinthelate1960sasanexperiment.Itsgoalwastocreateatrulyresilientinformationnetwork—onethatcouldwithstandthelossofseveralcomputerswithoutpreventingtheothersfromcommunicating.Drivenbypotentialdisasterscenarios(suchasnuclearattack),theU.S.DepartmentofDefenseprovidedtheinitialfunding.TheearlyInternetwasmostlylimitedtoeducationalinstitutionsanddefensecontractors.Itflourishedasatoolforacademiccollaboration,allowingresearchersacrosstheglobetoshareinformation.Intheearly1990s,modemswerecreatedthatcouldworkoverexistingphonelines,andtheInternetbegantoopenuptocommercialusers.In1993,thefirstHTMLbrowserwascreated,andtheInternetrevolutionbegan..Itwouldbedifficulttodescribeearlywebsitesaswebapplications.Instead,thefirstgenerationofwebsitesoftenlookedmorelikebrochures,consistingmostlyoffixedHTMLpagesthatneededtobeupdatedbyhandbasicHTMLpageisalittlelikeaword-processingdocument—itcontainsformattedcontentthatcanbedisplayedonyourcomputer,butitdoesn’tactuallydoanything.ThefollowingexampleshowsHTMLatitssimplest,withadocumentthatcontainsaheadingandsinglelineoftext:
AnHTMLdocumenthastwotypesofcontent:
thetextandthetagsthattellthebrowserhowtoformatit.Thetagsareeasilyrecognizable,becausetheyoccurinsideangledbrackets(<
>
).HTMLdefinestagsfordifferentlevelsofheadings,paragraphs,hyperlinks,italicandboldformatting,horizontallines,andsoon.Forexample,<
h1>
SomeText<
/h1>
tellsthebrowsertodisplaySomeTextintheHeading1style,whichusesalarge,boldfont.Figure1-1showsthesimpleHTMLpageinabrowser.HTML2.0introducedthefirstseedofwebprogrammingwithatechnologycalledHTMLforms.HTMLformsexpandHTMLsothatitincludesnotonlyformattingtagsbutalsotagsforgraphicalwidgets,orcontrols.Thesecontrolsincludecommoningredientssuchasdrop-downlists,textboxes,andbuttons.Here’sasamplewebpagecreatedwithHTMLformcontrols:
HTMLformsallowwebapplicationdeveloperstodesignstandardinputpages.WhentheuserclickstheSubmitbuttononthepageshowninFigure1-2,allthedataintheinputcontrols(inthiscase,thetwocheckboxes)ispatchedtogetherintoonelongstringandsenttothewebserver.Ontheserverside,acustomapplicationreceivesandprocessesthedata.Amazinglyenough,thecontrolsthatwerecreatedforHTMLformsmorethantenyearsagoarestillthebasicfoundationthatyou’llusetobuilddynamicASP.NETpages!
Thedifferenceisthetypeofapplicationthatrunsontheserverside.Inthepast,whentheuserclickedabuttononaformpage,theinformationmighthavebeene-mailedtoasetaccountorsenttoanapplicationontheserverthatusedthechallengingCGI(CommonGatewayInterface)standard.Today,you’llworkwiththemuchmorecapableandelegantASP.NETplatform.TounderstandwhyASP.NETwascreated,ithelpstounderstandtheproblemsofotherwebdevelopmenttechnologies.WiththeoriginalCGIstandard,forexample,thewebservermustlaunchacompletelyseparateinstanceoftheapplicationforeachwebrequest.Ifthewebsiteispopular,thewebservermuststruggleundertheweightofhundredsofseparatecopiesoftheapplication,eventuallybecomingavictimofitsownsuccess.counterthisproblem,MicrosoftdevelopedISAPI(InternetServerApplicationProgrammingInterface),ahigher-levelprogrammingmodel.ISAPIsolvedtheperformanceproblembutatthecostofsignificantcomplexity.EvenafterISAPIdevelopersmasterthetrickyC++programminglanguage,theystilllieawakeatnightworryingaboutconfoundingissuessuchasmultithreading.ISAPIprogrammingisdefinitelynotforthefainthearted.ISAPIneverreallygoaway.Instead,Microsoftusedittobuildhigher-leveldevelopmentplatforms,suchasASPandASP.NET.Bothofthesetechnologiesallowdeveloperstoprogramdynamicwebpageswithoutworryingaboutthelow-levelimplementationdetails.Forthatreason,bothplatformshavebecomeincrediblysuccessful.TheoriginalASPplatformgarneredahugeaudienceofnearlyonemilliondevelopers.WhenASP.NETwasfirstreleased,itgeneratedevenmoreinterestasthecenterpieceofthe.NETFrame-work.Infact,ASP.NET1.0wasenthusiasticallyputtoworkindozensoflarge-scalecommercialwebsitesevenwhenitwasonlyinlatebeta.Despitehavingsimilarunderpinnings,ASPandASP.NETareradicallydifferent.ASPisascript-basedprogramminglanguagethatrequiresathoroughunderstandingofHTMLandagooddealofpainfulcoding.ASP.NET,ontheotherhand,isanobject-orientedprogrammingmodelthatletsyouputtogetherawebpageaseasilyasyouwouldbuildaWindowsapplication.Inmanyrespects,it’seasiertolearnASP.NETthantomasterASP,eventhoughASP.NETisfarmorepowerful.Atthesametimethatserver-sidewebdevelopmentwasmovingthroughanalphabetsoupoftechnologies,anewtypeofprogrammingwasgainingpopularity.Developersbegantoexperimentwiththedifferentwaystheycouldenhancewebpagesbyembed-dingmultimediaandminiatureappletsbuiltwithJavaScript,DHTML(DynamicHTML),andJavacode.Theseclient-sidetechnologiesdon’tinvolveanyserverprocessing.Instead,thecompleteapplicationisdownloadedtotheclientbrowser,whichexecutesitlocally.Thegreatestproblemwithclient-sidetechnologiesisthattheyaren’tsupportedequallybyallbrowsersandoperatingsystems.Oneofthereasonsthatwebdevelopmentissopopularinthefirstplaceisbecausewebapplicationsdon’trequiresetupCDs,down-loads,andothertedious(anderror-prone)deploymentsteps.Instead,awebapplicationcanbeusedonanycomputerthathasInternetaccess.Butwhendevelopersuseclient-sidetechnologies,theyencounterafewfamiliarheadaches.Suddenly,cross-browsercompatibilitybecomesaproblem.Developersareforcedtotesttheirwebsiteswithdifferentoperatingsystemsandbrowsers,andtheymightevenneedtodistributebrowserupdatestotheirclients.Inotherwords,theclient-sidemodelsacrificessomeofthemostimportantbenefitsofwebdevelopmentorthatreason,ASP.NETisdesignedasaserver-sidetechnology.AllASP.NETcodeexecutesontheserver.Whenthecodeisfinishedexecuting,theuserreceivesanordinaryHTMLpage,whichcanbeviewedinanybrowser.Figure1-3showsthedifferencebetweentheserver-sideandclient-sidemodel.Thesearesomeotherreasonsforavoidingclient-sideprogramming:
Isolation:
Client-sidecodecan’taccessserver-sideresources.Forexample,aclient-sideapplicationhasnoeasywaytoreadafileorinteractwithadatabaseontheserver(atleastnotwithoutrunningintoproblemswithsecurityandbrowsercompatibility).Security:
Enduserscanviewclient-sidecode.Andoncemalicioususersunderstandhowanapplicationworks,theycanoftentamperwithit.omecases,ASP.NETallowsyoutocombinethebestofclient-sideprogrammingwithserver-sideprogramming.Forexample,thebestASP.NETcontrolscanintelligentlydetectthefeaturesoftheclientbrowser.IfthebrowsersupportsJavaScript,thesecontrolswillreturnawebpagethatincorporatesJavaScriptforaricher,moreresponsiveuserinterface.However,nomatterwhatthecapabilitiesofthebrowser,yourcodeisalwaysexecutedontheserver.Statelimitations:
Toensureoptimumperformance,theWebisbuiltonstatelessprotocols,whichmeansassoonasapageissenttoauser,theconnectionisclosedandanyuser-specificinformationisdiscarded.ASPincludesasessionstatefeaturethatallowsprogrammerstoworkaroundthisproblem.Usingsessionstate,awebapplicationcanretaintemporaryinformationabouteachclientinservermemory.However,sessionstateisuselessinscenarioswhereawebsiteishostedbyseveralseparatewebservers.Inthisscenario,aclientmightaccessserverBwhileitssessioninformationistrappedonserverAandessentiallyabandoned.ASP.NETcorrectsthisproblembyallowingstatetobestoredinacentralrepository,suchasaseparateprocessoradatabasethatallserverscanaccess.ASP.NETdealswiththeseproblems(andmanymore)byintroducingacompletelynewmodelforwebpages.ThismodelisbasedonaremarkablepieceoftechnologycalledtheNETFramework.Youshouldunderstandthatthe.NETFrameworkisreallyaclusterofseveraltechnologies:
The.NETlanguages:
TheseincludeC#andVB.NET(VisualBasic.NET),theobject-orientedandmodernizedsuccessortoVisualBasic6.0;
theselanguagesalsoincludeJscript.NET(aserver-sideversionofJavaScript),J#(aJavaclone),andC++withManagedExtensionsheCLR(CommonLanguageRuntime):
Th