ASP.NET3.5编程
2009-4
Jesse Liberty、Dan Hurwitz、 Dan Mabarry 开明出版社 (2009-04出版)
(美) 丽波蒂 (美) 赫维茨 (美) 马哈里 著
1144
New ideas in web development are created all the time, and the speed with which they evolve into mature technologies is astounding. To its credit, Microsoft is one of the companies that continue to push the boundaries in web development. ASP.NET 3.5 is arguably the fastest, most efficient, most reliable, and best-supported way to create interactive web applications today. Combined with the development tools available from Microsoft (both free and commercial), it is incredibly easy to create websites that look great and perform well. The amount of code you need to write to implement quite complex things continues to reduce with each new version of ASP.NET. The ever-improving support that Visual Studio and ASP.NET have for Cascading Style Sheets (CSS), themes, and consistent layouts using master pages means it's even easier to make your sites look their best. Best of all, most of the "plumbing" (security, data access, layout, etc.) is taken care of for you by the .NET Framework and the controls that are built into ASP.NET. Want to switch from using an Access database to using SQL server? That'll take about five minutes. Want to let users log on to the site using their logon identities? That's built into ASP.NET along with four other methods of authentication. Want to make sure users don't accidentally enter the wrong type of data into a web page? You can do that without writing any code at all thanks to the built-in validation controls. .The list of possibilities is long, and with the release of ASP.NET 3.5, there are yet more new pieces in the Microsoft web development puzzle that weren't there before——and, promisingly, a number of pieces that will continue to appear in the future which we've previewed in Chapter 21 and will cover more fully in the next edition of this book.Until such time as the fifth edition arrives, here's a list of the new features you'll find in this edition:New ASP.NET 3.5 server controlsASP.NET 3.5 introduces a trio of new controls. The ListView is a new databound control, which for those already using ASP.NET, works much like a cross between a Repeater and a DataList without the pain of using either. Combine it With the second new control, the DataPager, and you've got the best templatebased data-bound control in ASP.NET today. We cover both in Chapter 8. The third new control is another data source control which uses LINQ statements rather than SQL or XPath commands to select, alter, or create data. It is called the LinqDataSource control and we cover it in Chapter 10.ASP. NET AJAX Extensions and the Control ToolkitAJAX has been around awhile now, but this is the first version of this book to cover it. In Chapters 3 through 5, we look at the various controls in the ASP.NET AJAX Extensions library that now form part of ASP.NET 3.5 and those in the Microsoft-sponsored AJAX Control Toolkit available from http://codeplex.com.WCF Web ServicesThose of you who are already using web services in your websites will be aware that .NET 3.0 introduced the Windows Communication Framework and within it a new type of slim-line (RESTful) web service. This makes a lot more sense to use in some scenarios than those introduced originally in .NET 1.0. Chapter 16 looks at both types, the difference between them, and how to create and use them within a website.LINQProbably the most compelling reason to look at .NET 3.5, the Language Integrated Query APl presents a brand-new way to qnery for data across multiple sources in a consistent way. As Chapter 10 will demonstrate, LINQ is in no way just another data API.New features in Visual Studio 2008new version of Visual Studio always includes a few new features and this edition is no different. In Chapter 2 we provide coverage of these new features, and in Chapter 20 we look at the new Web Deployment Project add-on for VS2008.Vista and IIS 7.0January 2007 saw the release of Windows Vista and with it a completely new version of Internet Information Services (IIS). Rewritten from scratch, IIS 7.0 is a completely different beast from its forebears, and this has a direct effect on forms-based security, site configuration, and deployment. Chapters 12, 18, and 20 will cover all these changes, respectively.Even Vista itself has a certain impact on the development process. Its tighter grip on account permissions means that certain VS2008 functions can be performed only by an administrator. Notes throughout the book will highlight where this is the case.Examples and sample databaseThe majority of the examples in this book have been completely reworked and the database-dependent ones now also use the lightweight AdventureWorksLT sample database.It's quite amazing just how deep and rich a feature set ASP.NET has on its own before you even start to consider the additional features of VS2008, IIS 7.0, C# 3.0, SQL Server, and the rest. Although we can't cover everything in minute detail, we hope this book does give you a good guide to working with ASP.NET 3.5 and its associated technologies.Learning or Programming?We have written two ASP.NET books: the one you are currently reading and another named Learning ASP.NET 3.5 (O'Reilly). Whereas that book is aimed at complete beginners wanting to ramp up their ASP.NET skills, this book is aimed at those with at least a basic knowledge of development with ASP.NET who want to explore it in more depth. It is a way marker, mapping out and describing the various aspects of development with ASP.NET to a point where the reader has enough knowledge of it to understand what he can do and how to strike out on his own to deeper, more involved areas of the topic.With this in mind, Programming ASP. NET 3.5 is not aimed specifically at the total newcomer to ASP.NET development, though arguably newcomers may gain the most from it over a period of time. Nor is it targeted at the ASP.NET guru who wants in-depth knowledge of operations at the protocol level, although we hope there are a few nuggets in here that such readers didn't already know, and that they may choose to use this book as a handy fallback if their memory fails them.Visual Basic Versus C#A quick note on Visual Basic versus C#: some people choose a .NET book based on the language in which the examples are given. That's a natural reaction, but it's really not necessary, and here's why: there is very little actual Visual Basic or C# code in any given ASP.NET application, and what there is, you can easily translate from one to the other "on inspection." Besides, the two languages are strikingly similar, and both produce the same output. If you know one, it's quite simple to learn the other. In fact, software tools are available that can convert one language to the other with amazing accuracy. Finally, ASP.NET programmers benefit terrifically by being "bilingual"——that is, having the ability to read C# and write Visual Basic (or vice versa).In the end, we had to choose one language over the other, and we elected to do the examples and exercises for this book in C#. However, if you prefer Visual Basic, you'll find every single example and exercise solution reproduced in Visual Basic free for download from this book's website, at http://www.oreilly.com/catalog/9780596529567.How This Book Is OrganizedHere is a summary of the chapters in this book and what you can expect from each:Chapter 1, Web Development in 2008Provides a short introduction to how .NET has grown between v2.0 and v3.5, and in which areas it will continue to grow.Chapter 2, Visual Studio 2008Explores Visual Studio 2008 and its new features since the previous version, and shows how you can use them to create ASP.NET applications.Chapter 3, Controls: Fundamental ConceptsIntroduces the five types of control you'll use to create an ASP.NET website, and how they differ from each other. This chapter also introduces the concept of events and postbacks on a page.Chapter 4, Basic ControlsLooks at all the text-, image-, and list-related ASP.NET Server controls and AJAX server controls installed by default into Visual Studio 2008. The chapter also looks at some of the controls in the AJAX Control Toolkit that extend the functionality of the basic controls.Chapter 5, More ControlsLooks at more advanced ASP.NET Server controls and AJAX server controls installed by default into Visual Studio 2008, including the Panel, UpdatePanel, Wizard, FileUpload, and Calendar controls.Chapter 6, Website FundamentalsShows you how to use the code behind a page effectively, and how to manage state in the otherwise stateless Web. This chapter also describes the life cycle of a web page in detail and shows you how to take advantage of advanced directives.Chapter 7, Data Source Controls and ConnectionsLooks at the ASP.NET data source controls, how to use them, and which sources of data can be used with which control.Chapter 8, Using Data-Aware ControlsExplores the various data-bound controls supplied with ASP.NET 3.5, including the new ListView control. This chapter also demonstrates how they use the DataSource controls shown in Chapter 7 to both retrieve and save data.Chapter 9, ADO.NETShows you the technology underlying the controls described in Chapters 7 and 8, so you understand how it all works and can take precise control when necessary.Chapter 10, Presenting LINQLooks at the brand-new LINQ API, how it can be used to query and join diverse sources of data, and how to make use of it within ASP.NET pages.Chapter 11, ValidationDemonstrates the various ASP.NET server controls dedicated to validating the contents of a form to ensure data consistency and protect against spoofing. ..Chapter 12, Forms-Based SecurityDescribes in detail how to implement forms-based security to constrain user access to your website over the Internet. In addition, this chapter demonstrates how to use either the default (SQL Express) database for this or how to create your SQL Server database and use that instead to create users and roles (groups) and to facilitate authentication and authorization.Chapter 13, Master Pages and NavigationDescribes some of the features that help you build professional-quality web applications. Master pages allow you to create a uniform look and feel throughout your application, and the navigation controls allow you to build site maps, menus, and breadcrumbs quickly and easily to facilitate navigation of large applications.Chapter 14, PersonalizationShows you how to allow your users to tailor the look and feel of your site to their own requirements, and how to store that information so that when lasers return, the site remembers their preferences and state.Chapter 15, Custom and User ControlsCovers the powerful yet easy-to-use technology that allows you to extend ASP.NET to create controls customized for your specific problem domain.Chapter 16, Web ServicesLooks at how to create and consume both ASP.NET and WCF web services, how to enable them in an AJAX environment and the various standard protocols used for services and their clients to talk to one another.Chapter 17, Caching and PerformanceLays out the various ways that some or all of an ASP.NET page can be cached on the server and the different toggles that will require it to be deleted from the cache and regenerated.Chapter 18, Application Logic and ConfigurationLooks at how information can be stored at the application level and how the web.config file can be used to alter the operating parameters of your website. In particular, you'll see how to use ItS 7.0 and the Web Site Administration Tool (WAT) to alter web. config and then how to create custom sections of web.config for your own specific use.Chapter 19, Tracing, Debugging, and Error HandlingExamines the various ways to detect errors during development in ASP.NET, and how to handle errors that occur in your production code.Chapter 20, DeploymentLooks at three different ways to deploy your website: by copying the site's file directly with XCOPY, by wrapping it up into an installer with a Web Setup Project, and finally by deploying it as a part of the build process with a Web Deployment Project. Chapter 21, Epilogue: From Now to vNextLast but not least, this chapter takes a brief look at the various .NET 3.5 web development-related beta projects currently available for download.Appendix A, Installing the AJAX Control ToolkitDemonstrates how to install the AJAX Control Toolkit used throughout the book.Appendix B, Relational Database Technology: A Crash CourseIntroduces the key concepts needed to use relational databases, such as SQL Server, used in this book.Appendix C, Keyboard ShortcutsDescribes all the keyboard shortcuts enabled in Visual Studio 2008 under its Web Development default settings.What You Need to Use This BookWe wrote this book using Visual Studio 2008 and SQL Server 2005 on a laptop running Windows Vista. You may want to copy this setup to follow the book, but any of the following will do:Operating systemsWindows XP or later will do, except to follow Chapter 18's look at IIS 7.0, which is available only for Windows Vista and Windows Server 2008.Visual StudioThe 2008 edition of Visual Web Developer (free to download) will be more than sufficient to follow this book. If you have a paid-for copy of Visual Studio 2008, so much the better.SQL ServerAny edition of SQL Server 2005 or 2008 will do. If you decide to follow this text using SQL Server 2008, please note that you will need to download a slightly different version of the sample database to follow the material in Chapters 7 through 10.Conventions Used in This BookThe following typographical conventions are used in this book:ItalicIndicates new terms, URLs, email addresses, filenames, file extensions, pathnames, directories, and Unix utilitiesConstant widthIndicates commands, options, switches, variables, attributes, keys, functions, types, classes, namespaces, methods, modules, properties, parameters, values, objects, events, event handlers, XML tags, HTML tags, macros, the contents of files, and the output from commandsConstant width boldShows commands or other text that should be typed literally by the userConstant width italicShows text that should be replaced with user-supplied valuesUsing Code ExamplesThis book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product's documentation does require permission.We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "Programming ASP. NET 3.5, Fourth Edition, by Jesse Liberty, Dan Hurwitz, and Dan Maharry. Copyright 2009 Jesse Liberty, Dan Hurwitz, and Dan Maharry, 978-0-596-52956-7."If you feel your use of code examples falls outside fair use or the permission given here, feel free to contact us at permissions@oreilly.com.We'd like to Hear from YouPlease address comments and questions concerning this book to the publisher:O'Reilly Media, Inc.1005 Gravenstein Highway NorthSebastopol, CA 95472800-998-9938 (in the United States or Canada)707-829-0515 (international or local)707-829-0104 (fax)We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:http ://www.oreilly.com/catalog/9780596529567To comment or ask technical questions about this book, send email to:bookquestions@oreilly.comFor more information about our books, conferences, Resource Centers, and the O'Reilly Network, see our website at:http://www.oreilly.comSafari Books OnlineWhen you see a Safari Books Online icon on the cover of your favorite technology book, that means the book is available online through the O'Reilly Network Safari Bookshelf.Safari offers a solution that's better than e-books. It's a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at http://safari.oreilly.com.AcknowledgmentsFrom Jesse LibertyThis book is the result of the extraordinary work of three teams: the ASP.NET developers at Microsoft, my coauthors who shouldered the responsibility to turn a good book on ASP.NET into a world-class tutorial on a tremendously expanded framework, and the editorial and production team at O'Reilly who contribute more than can ever be expressed. I am deeply grateful to you all.From Dan HurwitzI would like to once again thank Jesse for being an excellent colleague and good friend, and the fine folks at O'Reilly who made this book possible, especially John Osborn and Brian MacDonald. I also wish to acknowledge the outstanding contribution of our new coauthor, the other Dan. And as always, I especially Want to thank my wife and family for being so supportive.From Dan MaharryThere are a number of people connected to this project that I need to thank. Jesse and Dan H. were brave enough to let me work with them, and John Osborn was kind enough to suggest me in the first place. Lou Franco and Mike Pope also provided some additional text. Thanks to them. Having worked in publishing in a former life, I know how many others will also have touched this book before reaching you, the reader, so I thank them, too.Thirteen months is a long time to dedicate weekends and nights to a single project, so thanks to my family and friends for necessarily distracting me every so often.Last but not least
《ASP.NET 3.5编程(影印版)(上下)(第4版)》由微软技术专家JesseLiberty、DanHurwitz和DanMaharry所著,是学习如何使用微软的最新技术来构建动态互动网络应用程序的最佳书籍。通过《ASP.NET3.5编程》你将快速学习使用微软的流行网络开发技术和VisualStudio2008来创建具有很高水准的应用程序。这本更新后的畅销书提供了全面而又易于理解的信息来帮助你使用几项.NET3.5的技术,加快开发速度并且提高网络应用程序的性能——包括使用ASP.NETAJAX的互动用户界面,应用LINQ进行数据访问和用WindowsCommunicationFoundation(WCF)来创建网络服务。 《ASP.NET3.5编程》包含例子和示例代码让你探索深层次的ASP.NET开发技术。通过《ASP.NET 3.5编程(影印版)(上下)(第4版)》,你将: 学习AJAX和ASP.NET服务器控制,包括使用VisualStudio2008 探索如何使用DataSource和ADO.NET中的数据约束控制 使用新的LINQ应用程序接口以及在ASP.NET网页中应用它 使用MasterPages来为你的整个应用程序创建统一的外观和感受 运用浏览控制来轻易地构建站点地图、菜单和网页导航 通过WCF来构建和使用各种网络服务 在开发过程中发现错误并在你的产品代码中处理这些错误 学习如何配置和部署你的网站
作者:(美国)Jesse Liberty (美国)Dan Hurwitz (美国)Dan MabarryJesse Liberty是O'Reilly的畅销书《Learning ASP.NET 3.5》《Programming C# 3.0》和《Programming .NET 3.5》的作者。Dan Hurwitz是Sterling Solutions有限公司的总裁,他提供编程和数据库开发的外包服务。Dan Maharry是Co-operative Web的高级开发人员,Co-operative是一个在英国的软件开发人员的合作组织。
上卷.Preface1. Web Development in 2008AJAX.NET Framework 3.0 and 3.5Visual Studio 2008Internet Information Services 7.0Beyond 2008On to VS20082. Visual Studio 2008First Sight: The Start PageCreating Your First Web PageProjects and SolutionsThe Integrated Development Environment3. Controls: Fundamental ConceptsEventsASP.NET Server ControlsAJAX Server ControlsHTML Server ControlsClient-Side Processing4. Basic ControlsVisual Studio Is Not MandatoryWeb Forms: Plain or AJAX?Label Controls and Literal ControlsTextBox ControlHiddenField ControlButton ControlsHyperLink ControlImagesSelecting Values5. More ControlsPanel ControlsThe UpdatePanel ControlMultiView and View ControlsThe Wizard ControlThe FileUpload ControlThe AdRotator ControlThe Calendar Control6. Website FundamentalsThe Page ClassThe Code-Behind FileMoving to Another PageStateLife CycleDirectives7. Data Source Controls and ConnectionsSources of Data and DataSource ControlsUsing the ObjectDataSource ControlUsing the XmlDataSource ControlUsing the SqlDataSource ControlTracking the Data Source with Events8. Using Data-Aware ControlsHierarchical Data ControlsTabular Data ControlsLists of DataOne Record at a Time: DetailsViewMany Records at a Time: GridViewTemplated Controls9. ADO. NETThe ADO.NET Object ModelGetting Started with ADO.NETCreating Data Objects by HandStored ProceduresUpdating with SQL and ADO.NETUpdating Data with TransactionsBinding to Business Objects10. Presenting LINQDeconstructing LINQLINQ ProvidersLINQ to XMLLINQ to SQL下卷11. ValidationThe RequiredFieldValidatorThe Summary ControlThe Compare ValidatorRange CheckingRegular ExpressionsCustom ValidationValidation Groups12. Forms-Based SecurityAuthenticationSetting Up Forms-Based Authentication13. Master Pages and NavigationMaster PagesNavigationFiltering Based on Security14. PersonalizationCreating Personalized WebsitesThemes and SkinsWeb Parts15. Custom and User ControlsUser ControlsCustom ControlsDerived ControlsComposite Controls16. Web ServicesIntroducing Web ServicesUnderstanding Web Service Protocols and StandardsUsing SOAP Web ServicesDeveloping an ASP.NET SOAP Web ServiceCalling the Web ServiceDeveloping a WCF Web ServiceCreating and Consuming AJAX-Enabled Web ServicesIntroducing REST and JSONLearning More About Web Services17. Caching and PerformanceTypes of CachingData CachingOutput CachingFragment Caching: Caching Part of a PageObject CachingThe HttpCachePolicy ClassPerformanceBenchmarking and Profiling18. Application Logic and ConfigurationIntroducing IIS 7.0Application-Wide LogicConfiguring the ApplicationModifying web.config with IIS 7.0Web Site Administration ToolCustom Configuration Sections19. Tracing, Debugging, and Error HandlingCreating the Sample ApplicationTracingDebuggingError HandlingCustom Error Pages20. DeploymentAssembliesLocal DeploymentGlobal DeploymentWindows InstallerWeb Deployment Projects21. Epilogue: From Nowto vNext(Some of) The Winnowing ProcessOn the StoveOn the Far HorizonA. Installing the AJAX Control ToolkitB. Relational Database Technology: A Crash CourseC. Keyboard ShortcutsIndex
插图:ExtemaI ToolsDepending on the options selected at the time VS2008 was installed on yourmachine,you may have one or more external tools available on the Tools menu.These might include tools such as Create GUID or Dotfuscator Community Edition.(Use of these tools is beyond the scope of this book.)The Tools External Tools command allows you to add additional external tools to the Tools menu.When you select it,you are presented with the External Tools dialog box.This dialog box has fields for the tool title,the command to execute the tool,any arguments and the initial directory,and several checkboxes for different behaviors.Import and Export SettingsThe Import and Export Settings command brings up the Import and Export Settings dialog box,which is a wizard for importing and exporting IDE environment settings. With this wizard,you can transfer your carefully wrought IDE settings from one machine to the next.CustomizeThe Customize command allows you to customize many aspects of the IDE user interface.(The Options command,described in the following section,allows you to set other program options.)It brings up the Customize dialog box,which has two tabs and a button,allowing customization in three different areas.
“SDP.NET 3.5是当今毫无争议的最快、最有效、最可靠和支持最好的用于创建互动网络应用程序的方式。” ——摘自本书前言
《ASP.NET3.5编程(影印版)(上卷·第4版)》为开明出版社出版发行。