Evjen ffirs.tex V3-02/17/2009 12:21am Pagei Professional ASP.NET 3.5 SP1 Edition In C# and VB Evjen ffirs.tex V3-02/17/2009 12:21am Pageii Evjen ffirs.tex V3-02/17/2009 12:21am Pageiii Professional ASP.NET 3.5 SP1 Edition In C# and VB Bill Evjen Scott Hanselman Devin Rader WileyPublishing,Inc. Evjen ffirs.tex V3-02/17/2009 12:21am Pageiv Professional ASP.NET 3.5 SP1 Edition: In C# and VB Publishedby WileyPublishing,Inc. 10475CrosspointBoulevard Indianapolis,IN46256 www.wiley.com Copyright2009byWileyPublishing,Inc.,Indianapolis,Indiana PublishedsimultaneouslyinCanada ISBN:978-0-470-47826-4 ManufacturedintheUnitedStatesofAmerica 10987654321 LibraryofCongressCataloging-in-PublicationData Evjen,Bill. ProfessionalASP.NET3.5SP1edition:inC#andVB/BillEvjen,ScottHanselman,DevinRader. p.cm. Includesindex. ISBN978-0-470-47826-4(cloth/cd-rom) 1. Activeserverpages.2. Microsoft.NET.3. C#(Computerprogramlanguage)4. MicrosoftVisualBASIC. I.Hanselman,Scott.II.Rader,Devin,1976-III.Title. TK5105.8885.A26E962009 006.7’882—dc22 2009004158 Nopartofthispublicationmaybereproduced,storedinaretrievalsystemortransmittedinanyformorbyany means,electronic,mechanical,photocopying,recording,scanningorotherwise,exceptaspermittedunderSections 107or108ofthe1976UnitedStatesCopyrightAct,withouteitherthepriorwrittenpermissionofthePublisher,or authorizationthroughpaymentoftheappropriateper-copyfeetotheCopyrightClearanceCenter,222Rosewood Drive,Danvers,MA01923,(978)750-8400,fax(978)646-8600.RequeststothePublisherforpermissionshouldbe addressedtothePermissionsDepartment,JohnWiley&Sons,Inc.,111RiverStreet,Hoboken,NJ07030,(201) 748-6011,fax(201)748-6008,oronlineathttp://www.wiley.com/go/permissions. LimitofLiability/DisclaimerofWarranty:Thepublisherandtheauthormakenorepresentationsorwarrantieswith respecttotheaccuracyorcompletenessofthecontentsofthisworkandspecificallydisclaimallwarranties, includingwithoutlimitationwarrantiesoffitnessforaparticularpurpose.Nowarrantymaybecreatedorextended bysalesorpromotionalmaterials.Theadviceandstrategiescontainedhereinmaynotbesuitableforevery situation.Thisworkissoldwiththeunderstandingthatthepublisherisnotengagedinrenderinglegal,accounting, orotherprofessionalservices.Ifprofessionalassistanceisrequired,theservicesofacompetentprofessionalperson shouldbesought.Neitherthepublishernortheauthorshallbeliablefordamagesarisingherefrom.Thefactthatan organizationorWebsiteisreferredtointhisworkasacitationand/orapotentialsourceoffurtherinformation doesnotmeanthattheauthororthepublisherendorsestheinformationtheorganizationorWebsitemayprovide orrecommendationsitmaymake.Further,readersshouldbeawarethatInternetWebsiteslistedinthisworkmay havechangedordisappearedbetweenwhenthisworkwaswrittenandwhenitisread. ForgeneralinformationonourotherproductsandservicespleasecontactourCustomerCareDepartmentwithinthe UnitedStatesat(877)762-2974,outsidetheUnitedStatesat(317)572-3993orfax(317)572-4002. Trademarks:Wiley,theWileylogo,Wrox,theWroxlogo,WroxProgrammertoProgrammer,andrelatedtradedress aretrademarksorregisteredtrademarksofJohnWiley&Sons,Inc.and/oritsaffiliates,intheUnitedStatesand othercountries,andmaynotbeusedwithoutwrittenpermission.Allothertrademarksarethepropertyoftheir respectiveowners.WileyPublishing,Inc.,isnotassociatedwithanyproductorvendormentionedinthisbook. Wileyalsopublishesitsbooksinavarietyofelectronicformats.Somecontentthatappearsinprintmaynotbe availableinelectronicbooks. Evjen fauth.tex V3-02/17/2009 12:13am Pagev About the Authors BillEvjenisanactiveproponentof.NETtechnologiesandcommunity-basedlearninginitiativesfor .NET.Hehasbeenactivelyinvolvedwith.NETsincethefirstbitswerereleasedin2000.Inthesameyear, BillfoundedtheSt.Louis.NETUserGroup(www.stlnet.org),oneoftheworld’sfirstsuchgroups.Bill isalsothefounderandformerexecutivedirectoroftheInternational.NETAssociation(www.ineta.org), whichrepresentsmorethan500,000membersworldwide.BasedinSt.Louis,Missouri,USA,Billisan acclaimedauthorandspeakeronASP.NETandXMLWebServices.Hehasauthoredorco-authored morethanfifteenbooksincludingProfessionalC#2008,ProfessionalVB2008,ASP.NETProfessionalSecrets, XMLWebServicesforASP.NET,andWebServicesEnhancements:UnderstandingtheWSEforEnterprise Applications(allpublishedbyWileyPublishing,Inc.).Inadditiontowriting,Billisaspeakeratnumerous conferences,includingDevConnections,VSLive,andTechEd.Alongwiththeseitems,Billworksclosely withMicrosoftasaMicrosoftRegionalDirectorandanMVP.BillistheGlobalHeadofPlatformArchitec- tureforLipper(www.lipperweb.com),aspartofThomsonReuters,theinternationalnewsandfinancial servicescompany.HegraduatedfromWesternWashingtonUniversityinBellingham,Washington,with aRussianlanguagedegree.Whenheisn’ttinkeringonthecomputer,hecanusuallybefoundathis summerhouseinToivakka,[email protected] ScottHanselmanworksforMicrosoftasaSeniorProgramManagerintheDeveloperDivision,aim- ingtospreadthegoodwordaboutdevelopingsoftware,mostoftenontheMicrosoftstack.Before thisheworkedineFinancefor6+yearsandbeforethathewasaPrincipalConsultantaMicrosoft Partnerfornearly7years.HewasalsoinvolvedinafewthingsliketheMVPandRDprogramsand willspeakaboutcomputers(andotherpassions)wheneversomeonewilllistentohim.Heblogsat http://www.hanselman.comandpodcasts at http://www.hanselminutes.comandcontributesto http://www.asp.net,http://www.windowsclient.net,andhttp://www.silverlight.net. DevinRaderisaProductManagerontheInfragisticsWebClientteam,responsibleforleadingthe creationofInfragisticsASP.NETandSilverlightproducts.Devinisalsoanactiveproponentandmem- berofthe.NETdevelopercommunity,beingaco-founderoftheSt.Louis.NETUserGroup,anactive memberoftheNewJersey.NETUserGroup,aformerboardmemberoftheInternational.NETAssoci- ation(INETA),andaregularspeakeratusergroups.HeisalsoacontributingauthorontheWroxtitle Silverlight1.0andatechnicaleditorforseveralotherWroxpublicationsandhaswrittencolumnsfor ASP.NETPromagazine,aswellas.NETtechnologyarticlesforMSDNOnline.Youcanfindmoreof Devin’smusingsatwww.geekswithblogs.com/devin. Evjen fauth.tex V3-02/17/2009 12:13am Pagevi Evjen fcredit.tex V3-02/17/2009 12:14am Pagevii Credits DevelopmentEditor VicePresidentandExecutiveGroupPublisher LoriCerreto RichardSwadley TechnicalEditor VicePresidentandExecutivePublisher AlexeiGorkov BarryPruett ProductionEditor AssociatePublisher DanielScribner JimMinatel CopyEditor ProjectCoordinator,Cover NancyRapoport LynseyStanford EditorialManager Proofreader MaryBethWakefield PublicationServices,Inc. ProductionManager Indexer TimTate J&JIndexing Evjen fcredit.tex V3-02/17/2009 12:14am Pageviii Evjen fack.tex V3-02/17/2009 12:14am Pageix Acknowledgments IhavesaiditbeforeandI’llsayitagain:Writingabookmayseemlikethegreatestofsoloendeavors,but itrequiresalargeteamofpeopleworkingtogethertogettechnicalbooksoutthedoor--andthisbookis noexception.Firstandforemost,IwouldliketothankJimMinatelofWroxforgivingmetheopportunity towritetheoriginalASP.NETbook,whichthenledtothisspecialedition.Thereisnothingbetterthan gettingtheopportunitytowriteaboutyourfavoritetopicfortheworld’sbestpublisher! BesidesJim,IworkedwithAdaobiObiTultononthefirsteditionandthenLoriCerretoasdevelopment editorandNancyRapoportascopyeditoronthisSP1Edition.Withouttheirefforts,thisbookwouldnot havehappened. IworkedcloselywithScottHanselmanandDevinRaderontheoriginaleditionofthisbook,andthese guysdeservealotofthanks.Iappreciateyourhelp(andDevin,Iappreciatethenewappendixforthis edition)andadvicethroughouttheprocess.Thanksguys! Finally,thankstomyentirefamily.BookwritingisadevilindisguiseasitissomethingthatIlovetodo butatthesametime,takeswaytoomuchtimeawayfrommyfamily.Thankstomyfamilyforputting upwiththisandforhelpingmegetthesebooksoutthedoor.Iloveyouall. —BillEvjen