外文翻译 - ASP.NET   C#版_第1页
外文翻译 - ASP.NET   C#版_第2页
外文翻译 - ASP.NET   C#版_第3页
外文翻译 - ASP.NET   C#版_第4页
外文翻译 - ASP.NET   C#版_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

外文原文ASP.NET2.0inC#ASP(ActiveServerPages)isarelativelynewtechnologythatsalreadyleaptthroughseveralstagesofevolution.Itwasintroducedaboutsevenyearsagoasaneasywaytoadddynamiccontenttoordinarywebpages.Sincethen,itsgrownintosomethingmuchmoreambitious:aplatformforcreatingadvancedwebapplications,includinge-commerceshops,data-drivenportalsites,andjustaboutanythingelseyoucanfindontheInternet.ASP.NET2.0isthelatestversionofASP,anditrepresentsthemostdramaticchangeyet.WithASP.NET,developersnolongerneedtopastetogetherajumbleofHTMLandscriptcodeinordertoprogramtheWeb.Instead,youcancreatefull-scalewebapplicationsusingnothingbutcodeandadesigntoolsuchasVisualStudio2005.Thecostofallthisinnovationisthelearningcurve.Notonlydoyouneedtolearnhowtouseanadvanceddesigntool(VisualStudio)andatoolkitofobjects(the.NETFramework),youalsoneedtomasteraprogramminglanguagesuchasC#.TheInternetbeganinthelate1960sasanexperiment.Itsgoalwastocreateatrulyresilientinformationnetworkonethatcouldwithstandthelossofseveralcomputerswithoutpreventingtheothersfromcommunicating.Drivenbypotentialdisasterscenarios(suchasnuclearattack),theU.S.DepartmentofDefenseprovidedtheinitialfunding.TheearlyInternetwasmostlylimitedtoeducationalinstitutionsanddefensecontractors.Itflourishedasatoolforacademiccollaboration,allowingresearchersacrosstheglobetoshareinformation.Intheearly1990s,modemswerecreatedthatcouldworkoverexistingphonelines,andtheInternetbegantoopenuptocommercialusers.In1993,thefirstHTMLbrowserwascreated,andtheInternetrevolutionbegan.Itwouldbedifficulttodescribeearlywebsitesaswebapplications.Instead,thefirstgenerationofwebsitesoftenlookedmorelikebrochures,consistingmostlyoffixedHTMLpagesthatneededtobeupdatedbyhandbasicHTMLpageisalittlelikeaword-processingdocumentitcontainsformattedcontentthatcanbedisplayedonyourcomputer,butitdoesntactuallydoanything.ThefollowingexampleshowsHTMLatitssimplest,withadocumentthatcontainsaheadingandsinglelineoftext:AnHTMLdocumenthastwotypesofcontent:thetextandthetagsthattellthebrowserhowtoformatit.Thetagsareeasilyrecognizable,becausetheyoccurinsideangledbrackets().HTMLdefinestagsfordifferentlevelsofheadings,paragraphs,hyperlinks,italicandboldformatting,horizontallines,andsoon.Forexample,SomeTexttellsthebrowsertodisplaySomeTextintheHeading1style,whichusesalarge,boldfont.Figure1-1showsthesimpleHTMLpageinabrowser.HTML2.0introducedthefirstseedofwebprogrammingwithatechnologycalledHTMLforms.HTMLformsexpandHTMLsothatitincludesnotonlyformattingtagsbutalsotagsforgraphicalwidgets,orcontrols.Thesecontrolsincludecommoningredientssuchasdrop-downlists,textboxes,andbuttons.HeresasamplewebpagecreatedwithHTMLformcontrols:HTMLformsallowwebapplicationdeveloperstodesignstandardinputpages.WhentheuserclickstheSubmitbuttononthepageshowninFigure1-2,allthedataintheinputcontrols(inthiscase,thetwocheckboxes)ispatchedtogetherintoonelongstringandsenttothewebserver.Ontheserverside,acustomapplicationreceivesandprocessesthedata.Amazinglyenough,thecontrolsthatwerecreatedforHTMLformsmorethantenyearsagoarestillthebasicfoundationthatyoullusetobuilddynamicASP.NETpages!Thedifferenceisthetypeofapplicationthatrunsontheserverside.Inthepast,whentheuserclickedabuttononaformpage,theinformationmighthavebeene-mailedtoasetaccountorsenttoanapplicationontheserverthatusedthechallengingCGI(CommonGatewayInterface)standard.Today,youllworkwiththemuchmorecapableandelegantASP.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,itseasiertolearnASP.NETthantomasterASP,eventhoughASP.NETisfarmorepowerful.Atthesametimethatserver-sidewebdevelopmentwasmovingthroughanalphabetsoupoftechnologies,anewtypeofprogrammingwasgainingpopularity.Developersbegantoexperimentwiththedifferentwaystheycouldenhancewebpagesbyembed-dingmultimediaandminiatureappletsbuiltwithJavaScript,DHTML(DynamicHTML),andJavacode.Theseclient-sidetechnologiesdontinvolveanyserverprocessing.Instead,thecompleteapplicationisdownloadedtotheclientbrowser,whichexecutesitlocally.Thegreatestproblemwithclient-sidetechnologiesisthattheyarentsupportedequallybyallbrowsersandoperatingsystems.OneofthereasonsthatwebdevelopmentissopopularinthefirstplaceisbecausewebapplicationsdontrequiresetupCDs,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-sidecodecantaccessserver-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):TheCLRistheenginethatexecutesall.NETprogramsandprovidesautomaticservicesfortheseapplications,suchassecuritychecking,memorymanagement,andoptimization.The.NETFrameworkclasslibrary:Theclasslibrarycollectsthousandsofpiecesofprebuiltfunctionalitythatyoucan“snapin”toyourapplications.Thesefeaturesaresometimesorganizedintotechnologysets,suchasADO.NET(thetechnologyforcreatingdatabaseapplications)andWindowsForms(thetechnologyforcreatingdesktopuserinterfaces).ASP.NET:Thisistheenginethathostswebapplicationsandwebservices,withalmostanyfeaturefromthe.NETclasslibrary.ASP.NETalsoincludesasetofweb-specificservices.UsualStudio:Thisoptionaldevelopmenttoolcontainsarichsetofproductivityanddebuggingfeatures.TheVisualStudiosetupCDs(orDVD)includethecomplete.NETFramework,soyouwontneedtodownloaditseparately.Interestingly,C#andVB.NETareactuallyfarmoresimilarthanJavaandC#orthanVB6andVB.NET.Thoughthesyntaxisdifferent,bothC#andVB.NETusethe.NETclasslibraryandaresupportedbytheCLR.Infact,almostanyblockofC#codecanbetranslated,linebyline,intoanequivalentblockofVB.NETcode.Anoccasionallanguagedifferencepopsup(forexample,C#supportsalanguagefeaturecalledanonymousmethods,whileVB.NETdoesnt),butforthemostpart,adeveloperwhohaslearnedone.NETlanguagecanmovequicklyandefficientlytoanothershort,bothC#andVB.NETareelegant,modernlanguagesthatareidealforcreatingthenextgenerationofwebapplications.NET1.0introducedcompletelynewlanguages.However,thechangesinthe.NET2.0languagesaremuchmoresubtle.BothC#2005andVB2005addafewnewfeatures,butmostpartsoftheselanguagesremainunchanged.Asaresult,anycodewrittenaccordingtoversion1.0oftheC#languagewillworkidenticallywithversion2.0.InChapters2and3,youllsortthroughthesyntaxofC#andlearnthebasicsofobject-orientedprogramming.Bylearningthefundamentalsbeforeyoustartcreatingsimplewebpages,youllfacelessconfusionandmovemorerapidlytoadvancedtopicssuchasdatabaseaccessandwebservicesheCLRrunsonlyILcode,whichmeansithasnoideawhich.NETlanguageyouoriginallyused.Notice,however,thattheCLRactuallyperformsanothercompilationstepittakestheILcodeandtransformsittonativemachinelanguagecodethatsappropriateforthecurrentplatform.Thisstepoccurswhentheapplicationislaunched,justbeforethecodeisactuallyexecuted.InanASP.NETapplication,thesemachine-specificfilesarecachedwhilethewebapplicationisrunningsothattheycanbereused,ensuringoptimumperformance.Youmightwonderwhy.NETcompilersdontcompilestraighttomachinecode.Thereasonisthatthemachinecodedependsonseveralfactors,includingtheCPU.Forexample,ifyoucreatemachinecodeforacomputerwithanIntelprocessor,thecompilermaybeabletouseHyper-Threadingtoproduceenhancedcode.Thismachine-specificversionisntsuitablefordeploymenttoothercomputers,becausenoguaranteeexiststhattheyreusingthesameprocessor.AnotherwelcomechangeinVisualStudio2005isthesupportfordifferentcodingmodels.WhileVisualStudio.NET2003lockeddevelopersintooneapproach,VisualStudio2005supportsarangeofdifferentcodingmodels,makingitaflexible,all-purposedesigntool.ThatmeansyoucanchoosetoputyourHTMLtagsandeventhandlingcodeinthesamefileorinseparatefileswithoutcompromisingyourabilitytouseVisualStudioandbenefitfromhelpfulfeaturessuchasIntelliSense.中文翻译ASP.NETC#版ASP(动态服务器主页)是一种较新的技术,它已经过几个阶段的发展(进化).它是怎么诞生的呢?在七年前,它作为一种简单的方法来往普通网页里添加动态内容。自从那时以后,它的发展势头强劲:作为高级网页程序的开发平台,包括:电子商务网站、基于事件驱动的门户网站和你在网上能看到的其他所有东西。ASP.NET2.0是ASP的最新版本,而且拥有最让人激动的更新。在ASP.NET帮助下,在网络编程时,开发者不再把一大堆HTML源码和脚本代码杂乱地放在同一页面上。你可以完全使用代码和工具(VisualStudio2005)来创建网页程序。这些创新的代价仅仅是多学一些东西。你要学一些高级开发工具(VisualStudio)和工具包(the.NETFramework),而且你需要精通一门编程语言,如C。网络发展的演化因特网是在1960年末在试验中诞生的。它的目标是:建立一个真实的、有弹性的信息网络可以经受的起若干数量的电脑的崩溃,而不至于阻断其他电脑的正常通信。经得起潜在的重大灾难(如核武器攻击)。美国国防部提供了刚开始的研究基金。最早的因特网局限在教育机构和从事国防的单位。它因为作为学术研究的一种工具而繁荣,它让全球的研究人员可以彼此共享信息。到了1990初,伟大的“猫”诞生了,它通过电话线工作,从此,因特网向商业用户打开了大门。在1993年,第一个HTML浏览器诞生了,标志着因特网革命的到来。我们很难把最早的网页称为网页序。第一代的网页看起来更像小册子:主要由固定的HTML页面构成,这些也都需要手动修改。一个简单的HTML页面有点像一个字处理文档它包含了格式化的内容,可以在你的电脑上显示,但是并不完成其他任何功能。上面的就是一个最简单的例子,文档包括头信息和单行文本。一个HTML文档有两种类型的内容:文本和标记(告诉浏览器如何格式化)。这些标记很容易辨认,因为它们总是出现在之间。HTML定义了不同级别的标题、段落、超链接、斜体和粗体格式、水平线等。举个例子:某个文本,告诉浏览器用标题1的格式来显示这个文本,就是用最大的黑体字来显示。图11显示了这个页面在浏览器中的效果。提示:你不需要精通HTML就能进行ASP.NET网页编程,虽然它(HTML)是很有用的。为了快速介绍一下HTML,给大家介绍一个网上的优秀HTML指南。HTML2.0首次引入了一个网页编程的新技术,称为HTML表单。HTML表单扩展了HTML的功能,不仅包含了格式化标签,而且包含了窗体小部件或者叫控件。这些控件包含了普通的功能部件,如下拉列表、文本框和按钮。下面是一个由HTML表单控件创建的网页。网页表单允许网页程序设计师设计标准的输入页面。当用户单击图12的提交按钮,所有在输入控件中的数据(在这个例子中是两个复选框)将打包成一个长字符串,接着发送到服务器。在服务器端,一个客户程序接收和处理这些数据。令人惊奇的是:这些为HTML表单创建有超过十年之久的控件仍然是你用来创建ASP.NET页面的基础。不同的是这些程序控件将运行在服务器端。在过去,当用户单击一个表单页面的按钮时,信息要通过e-mail来发送或者使用在服务器端运行的程序(通过CGI标准)。今天,你将可以使用更强大、更优雅的ASP.NET平台。理解ASP.NET的创建原因可以帮助我们了解其他网页开发技术遇到的问题。在原始的CGI标准下,举个例子,网页服务器必须为每个网页请求建立一个单独的程序实例。如果这个网页很受人们欢迎(那访问者将很多),那么网页服务器就要经受得起数以百计的独立程序副本,这样最终导致服务器反而因为受欢迎而成为受害者。为了解决这个问题,微软开发了ISAPI(网络服务程序编程接口),一个高层次的编程模型。ISAPI解决了性能问题,但是付出了复杂性的代价。即使ISAPI开发者是个C编程老手,他仍然晚上担心到失眠,因为会遇到多线程处理这样让人麻烦的问题。ISAPI编程是给那些坚强的“夜猫子”,不是给那些懦弱的人。ISAPI并没有真正消失,取代它的是,微软利用它建立了一个更高级的开发平台,如ASP和ASP.NET。这两种技术都可以使开发者编写动态网页,而不需要担心底层的执行细节。由于这个原因,这两个平台成功到令人难以置信。最初的ASP平台吸引了将近一百万的开发人员。当ASP.NET第一次发布时,作为.NETFramework的核心部件受到人们更多关注。事实上,ASP.NET1.0已经在数十个大型商业网络中得到应用,虽然它还在最后的测试阶段。虽然拥有类似的基础,ASP和ASP.NET有根本的不同。ASP是基于脚本的编程语言,需要全面理解HTML,而且还要经过一大堆痛苦的编程训练。而ASP.NET,在另一方面,是面向对象的编程模型,建立网页页面就像建立桌面程序一样容易。在很多方面,学会ASP.NET比精通ASP要容易,而且ASP.NET功能更加强大。同时,服务器端的网络发展为从技术的字母形花片汤到广受欢迎的一类编程开发人员开始试着使用嵌入多媒体、JavaScript的小程序、DHTML和Java代码来增强网页的功能。这些基于客户端的技术不需要通过服务器的处理就能实现。所有的程序都(从服务器)下载到客户端浏览器,在本地执行。客户端技术的最大问题就是它们不被所有的浏览器和操作系统完美的支持。其中的一个原因就是网络开发太受欢迎了,首先是网络程序不需要通过CD安装、下载和其他单调的配置。取而代之的是,一个网络程序只要能上网的电脑就可以执行了。但是,一旦开发者使用客户端技术,他们就会遇到一些常见的问题:比如跨浏览器的兼容性。开发者就不得不在不同的浏览器和操作系统中测试他们的网页,甚至他们还要给用户发布浏览器更新。换句话说,客户端模型牺牲了网络程序最重要的优良特性。由于上述原因,ASP.NET被设计为服务器端技术。所有的ASP.NET代码都在服务器上执行。当代码执行完毕时,用户就会得到一个普通的HTML页面,这样任何浏览器都可以浏览了。图13显示了服务器端和客户端模型的不同。这里还有几条原因要避免客户端编程:孤立性:客户端代码无法访问服务器资源。举个例子,没有一种简单的方式让客户端可以读取一个在服务器上的文件或进行数据库连接。(至少不会遇到安全性和浏览器兼容性的问题)安全性:最终用户可以查看客户端代码。一旦有不怀好意的用户理解了程序是怎么工作的,他们就有可能乱来了。在某些方面,ASP.NET允许你通过服务器端编程结合最佳的客户端编程。举个例子:ASP.NET控件可以智能侦测客户端浏览器的属性。如果该浏览器支持JavaScript,那么这些控件将返回一个含有JavaScript的更多功能的页面。尽管如此,不管浏览器的功能有多强大,你的代码始终在服务器端执行。状态限制:为了保证最佳性能,网络设计成无状态的协议。意思就是:一旦页面已经传送给用户,连接就关闭了而且用户指定的信息也被丢弃了。ASP包括一个sessionstate(会话状态)特性允许程序员来解决这个问题。使用sessionstate,一个网页程序可以为每一个客户端暂时保存信息(保存在服务器的内存里)。尽管如此,

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论