Beginning ASP.NET Web Pages with Webmatrix®
Total Page:16
File Type:pdf, Size:1020Kb
BEGINNING ASP.NET WEB PAGES WITH WEBMatRIX® FOREWORD . xxiii INTRodUCTION . xxv CHaptER 1 Getting Started with WebMatrix . 1 CHaptER 2 Designing Web Pages . .. 21 CHaptER 3 Designing Websites . 53 CHaptER 4 Programming Your Site . 77 CHaptER 5 Adding User Interactivity . 115 CHaptER 6 AJAX and jQuery . 147 CHaptER 7 Packages . 179 CHaptER 8 Working with Files and Images . 197 CHaptER 9 Debugging and Error Handling . 219 CHaptER 10 Introduction to Data and Databases . 243 CHaptER 11 A Deeper Dive Into Data Access . 271 CHaptER 12 Security . 305 CHaptER 13 Optimizing Your Site . 333 CHaptER 14 Deploying Your Site . .. 357 APPENDIX Exercise Answers . .. 375 INDEX . 385 BEGINNING ASP.NET Web Pages with WebMatrix® BEGINNING ASP.NET Web Pages with WebMatrix® Mike Brind Imar Spaanjaars Beginning ASP.NET Web Pages with WebMatrix® Published by John Wiley & Sons, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2011 by John Wiley & Sons, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-1-118-05048-4 ISBN: 978-1-118-20348-4 (ebk) ISBN: 978-1-118-20350-7 (ebk) ISBN: 978-1-118-20349-1 (ebk) Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or pro- motional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the pub- lisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read. For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Wiley also publishes its books in a variety of electronic formats and by print-on-demand. Not all content that is available in standard print versions of this book may appear or be packaged in all book formats. If you have purchased a version of this book that did not include media that is referenced by or accompanies a standard print version, you may request this media by visiting http://booksupport.wiley.com. For more information about Wiley products, visit us at www.wiley.com. Library of Congress Control Number: 2011936929 Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other coun- tries, and may not be used without written permission. WebMatrix is a registered trademark of Microsoft Corporation. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc., is not associated with any product or vendor mentioned in this book. AboUT THE AUTHORS MIKE BRIND spent the first 20 years of his working life in a series of successful sales and marketing roles, towards the end of which he was introduced to HTML and databases. A dormant inner geek took over and Mike became very much more interested in developing websites than selling advertis- ing space on them. As well as on books such as those in the Wrox Beginner series, Mike became reliant on the enormous amount of free help provided by online communities while he learned his new craft. Mike is now one of the all-time leading contributors to the official ASP.NET forums athttp://forums.asp.net and is also a moderator there. As a result of his contributions to the ASP.NET community via the forums, and through his technical article site at www.mikesdotnetting.com, Mike received the Microsoft Most Valuable Professional (MVP) Award for ASP.NET in 2008, 2009, 2010, and 2011. Beginning ASP.NET Web Pages with WebMatrix is Mike’s first book. Mike is currently the Operations Director for ITEC Systems, a company that produces specialist software for recruitment agencies all around the world. Mike lives in Rochester in the UK with his wife of over 25 years, Anna. Together they have two daughters and a grandson. ImaR SpaaNJaaRs graduated in Leisure Management at the Leisure Management School in the Netherlands, but he quickly changed his career path into the Internet world. After working in the Internet business at various web agencies for thirteen years, he started up his own company called De Vier Koeden (http://devierkoeden.com), a small Internet agency specializing in consultancy and development of Internet and intranet applications with Microsoft technologies such as ASP.NET 4. He’s also the technical director of Dynamicweb Netherlands and Dynamicweb North America, two branches of the popular Danish CMS and eCommerce system Dynamicweb. Imar has written books on ASP.NET and Macromedia Dreamweaver, all published under the Wrox brand. He is also one of the top contributors to the Wrox Community Forum at p2p.wrox.com, where he shares his knowledge with fellow programmers. Since 2008, Imar has been rewarded with Microsoft’s Most Valuable Professional (MVP) award for his contributions to the ASP.NET community. Imar lives in Utrecht, the Netherlands, with his girlfriend, Fleur. You can contact him through his personal web site at http://imar.spaanjaars.com or by email at [email protected]. AboUT THE TECHNICAL EdItoR MICHAEL ApostoL graduated from the University of Oregon with a B.S. in Economics. He started his career working for Microsoft Corporation in Market Development. Michael has worked in both software development and information technology as an I.T. manager, programmer, and consul- tant for numerous companies in the Western United States in addition to a few trips to Europe as a software instructor. Presently, he is employed as a contractor writing SQL Server TSQL code for a company in Hawaii. He has thoroughly enjoyed his work as a technical editor with his last project being: Beginning Microsoft ASP.NET 4.0 by Imar Spaanjaars (2010, Wiley Publishing, Inc.). In his free time, Michael tries to get as much time possible with his adopted seven year old Ethiopian son, Geremu, and spouse, Melissa, outside in the sunshine. CREDIts ACQUISITIONS EdItoR PRODUCTION MANAGER Paul Reese Tim Tate PROJECT EdItoR VICE PRESIDENT AND EXECUTIVE GROUP Rosanne Koneval PUBLISHER Richard Swadley TECHNICAL EdItoR Michael Apostol VICE PRESIDENT AND EXECUTIVE PUBLISHER Neil Edde PRODUCTION EdItoR Rebecca Anderson AssoCIatE PUBLISHER Jim Minatel CopY EdItoR Kezia Endsley PROJECT CooRDINatoR, CovER Katie Crocker EdItoRIAL MANAGER Mary Beth Wakefield ComposItoR Craig Johnson, Happenstance Type-O-Rama FREELANCER EdItoRIAL MANAGER Rosemarie Graham PRoofREADER Nancy Carrasco AssoCIatE DIRECtoR OF MARKETING David Mayhew INDEXER Johnna VanHoose Dinse MARKETING MANAGER Ashley Zurcher CovER DESIGNER LeAndra Young BUSINEss MANAGER Amy Knies CovER ImaGE © Nikada ACKNowLEDGMENts I woULD LIKE to staRT by thanking Imar Spaanjaars, my co-author and fellow MVP, for recommend- ing me to Wrox for this project. I am also grateful for the advice and support he has provided as the book became reality. I would also like to thank Paul Reese for listening to Imar and taking a chance on me. I would also like to thank Michael J. Apostol for his contribution as Technical Editor and for Kezia Endsley for tirelessly translating my English into English. I am particularly appreciative of the efforts of Rosanne Koneval for her patience and diplomacy in guiding this particular author newbie through the process of getting a book done. Finally, I would like to thank my wife of over 25 years, Anna, for her support and understanding throughout the project. I lost count of how many times she asked “have you finished the book yet?” But at last, I can answer “Yes!” CoNTENts FOREWORD xxiii INTrodUCTioN xxv CHaptER 1: GEttING StaRTED WITH WEBMatRIX 1 Introducing WebMatrix 2 What Is WebMatrix? 2 Why Should You Use WebMatrix? 3 How Do You Acquire WebMatrix? 3 Introducing the ASP .NET Web