asp.net website programming...asp.net website programming problem – design – solution visual...

30
ASP.NET Website Programming Problem – Design – Solution Visual Basic® .NET Edition Marco Bellinaso Kevin Hoffman Visual Basic® .NET code provided by Demian Martinez and Norbert Martinez

Upload: others

Post on 25-Apr-2020

12 views

Category:

Documents


0 download

TRANSCRIPT

  • ASP.NET Website ProgrammingProblem – Design – Solution

    Visual Basic® .NET Edition

    Marco BellinasoKevin Hoffman

    Visual Basic® .NET code provided byDemian Martinez and Norbert Martinez

    C1.jpg

  • ASP.NET Website ProgrammingProblem – Design – Solution

    Visual Basic® .NET Edition

    Marco BellinasoKevin Hoffman

    Visual Basic® .NET code provided byDemian Martinez and Norbert Martinez

  • ASP.NET Website ProgrammingProblem – Design – SolutionVisual Basic®.NET EditionPublished byWiley Publishing, Inc.10475 Crosspoint BoulevardIndianapolis, IN 46256www.wiley.com

    Copyright © 2003 by Wiley Publishing, Inc., Indianapolis, Indiana

    Published simultaneously in Canada

    Library of Congress Card Number: 2003107088

    ISBN: 0-7645-4386-5

    Manufactured in the United States of America

    10 9 8 7 6 5 4 3 2 1

    1M/QU/QW/QT/IN

    No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by anymeans, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, orauthorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 RosewoodDrive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8700. Requests to the Publisher for permission shouldbe addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256,(317) 572-3447, fax (317) 572-4447, E-Mail: [email protected].

    LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: WHILE THE PUBLISHER AND AUTHOR HAVEUSED THEIR BEST EFFORTS IN PREPARING THIS BOOK, THEY MAKE NO REPRESENTATIONS OR WAR-RANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS BOOKAND SPECIFICALLY DISCLAIM ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FORA PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES REPRESENTA-TIVES OR WRITTEN SALES MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAYNOT BE SUITABLE FOR YOUR SITUATION. YOU SHOULD CONSULT WITH A PROFESSIONAL WHEREAPPROPRIATE. NEITHER THE PUBLISHER NOR AUTHOR SHALL BE LIABLE FOR ANY LOSS OF PROFITOR ANY OTHER COMMERCIAL DAMAGES, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL,CONSEQUENTIAL, OR OTHER DAMAGES.

    For general information on our other products and services or to obtain technical support, please contactour Customer Care Department within the U.S. at (800) 762-2974, outside the U.S. at (317) 572-3993 or fax(317) 572-4002.

    Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not beavailable in electronic books.

    Trademarks: Wiley, the Wiley Publishing logo, Wrox, the Wrox logo, the Wrox Programmer to Programmer logoand related trade dress are trademarks or registered trademarks of Wiley in the United States and other coun-tries, and may not be used without written permission. All other trademarks are the property of their respec-tive owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.

    www.wiley.com

  • Trademark AcknowledgmentsWrox has endeavored to provide trademark information about all the companies and productsmentioned in this book by the appropriate use of capitals. However, Wrox cannot guarantee theaccuracy of this information.

    CreditsAuthors Visual Basic .NET CodeMarco Bellinaso Demian MartinezKevin Hoffman Norbert Martinez

    Commissioning Editor Technical ReviewersDan Kent Mark Horner

    Don LeeTechnical Editors Dan MaharryDan Kent Christophe NasarreDianne Arrow Matthew RabinowitzDavid Barnes Marc H Simkin

    Index CoverAndrew Criddle Natalie O'Donnell

    Project Manager Production CoordinatorCharlotte Smith Sarah Hall

    Managing Editor ProofreaderLouay Fatoohi Chris Smith

  • About the Authors

    Marco BellinasoMarco Bellinaso lives in a small town close to Venice, Italy. He works as a software developer andtrainer for Code Architects Srl (www.codearchitects.com), an Italian company that specializes in.NET. He has been working with VB, C/C++, ASP, and other Microsoft tools for several years,specializing in User Interface, API, and ActiveX/COM design and programming, but is now spendingall his time on the .NET Framework, using C# and VB.NET.

    He's been working with the .NET Framework since the Beta 1, and is now particularly interested in e-commerce design and implementation solutions with SQL Server, ASP.NET, and web services, withboth C# and VB.NET. He is part of the VB-2-The-Max team (www.vb2themax.com), a popular websitefor VB and .NET developers, for which he writes articles and commercial software, such as add-ins forMS Visual Studio and other utilities for VB and .NET developers. In particular, he co-authored theaward-winning VB Maximizer VB6 add-in.

    Marco also loves writing and talking about technical stuff. He recently co-authored ASP.NET WebsiteProgramming – C# edition, Fast Track ASP.NET and Visual C#: a Guide for VB6 developers, all from WroxPress, and is also a contributing editor for two leading Italian programming magazines: ComputerProgramming and Visual Basic Journal (Italian licensee for Visual Studio Magazine). Reach him [email protected].

    AcknowledgmentsWriting this book has been a real pleasure to me. It gave me the opportunity to work with ASP.NET on a goodproject, and to improve my knowledge of the technology along the way. So it surely has been worth the effort! And ofcourse, everyone likes to be published writing about what they like to do and how to do it. :-)

    I owe many thanks to Wrox Press for giving me the opportunity to write the book: this is the most English I've everwritten, so I guess the editors and reviewers had some extra work with me, although they were so kind as to neverconfess it. Some of these people are Daniel Kent, David Barnes, and Dianne Arrow.

    Other people contributed to this project, in a way or another, now or in the past, and I'd like to mention at least afew names. First of all a really big thank you goes to Francesco Balena, famous speaker and author, and editor inchief of the Italian licensee of VBPJ (now Visual Studio Magazine). He reviewed and published an article about VBsubclassing that I wrote some years ago, when I had no editorial experience at all. Since that moment he hascontinued to help me by advising how to improve my writing style, pushing me to start writing in English,suggesting the hottest technology to study, and giving the opportunity to work on some cool software projects as partof the VB-2-The-Max team. Francesco, all this is greatly appreciated!

    Two other developers I work with for the Italian magazines, who helped me in different ways, are Dino Espositoand Alberto Falossi.

    Giovanni – Gianni – Artico is the person who initiated me in the programming art, suggesting to start with VBand then to learn C/C++ as well. Thank you for answering my questions when I was at the beginning, and for stillhelping me in some situations.

    A mention goes also to my closest friends. They still remember me after several "sorry, I can't come today" rebuttals,and have put up with me when I was under pressure and not the nicest person possible.

  • Last but not least I have to say thank you to my family, who bought my first computer and a lot of programmingbooks when I was in high school and couldn't buy all that stuff by myself. They didn't offer much moral supportduring the work – mostly because they didn't have a clue of what I was doing! I kept it a secret to almost everybody– I hope it will be a nice surprise. :-)

    Kevin HoffmanKevin has always loved computers and computer programming. He first got hooked when he received aCommodore VIC-20 from his grandfather, who had repaired it after finding it in the trash. He thenstarted a prolific but unprofitable career writing shareware games and utilities for electronic bulletinboard systems.

    He started working as a programmer while still in college, writing computer interfaces to solarmeasurement devices and various other scientific instruments. Moving to Oregon, he did everythingfrom technical support to tuning Unix kernels, and eventually working as an ASP programmer for800.COM, a popular on-line electronics retailer. From there he moved on to working on large,enterprise ASP applications.

    Then he finally found .NET, which he now spends 100% of his programming and learning efforts on. Abig C# fan, who would use it to do everything including brush his teeth if only he could figure out how,Kevin has been writing on .NET for Wrox since the middle of Beta 1. He plans to continue until we gettired of him. He's currently in Houston, Texas sweating a lot and working on web services and otherlarge-scale .NET applications.

    AcknowledgmentsI'd like to dedicate this book to the rest of my "family", without whom I could not have accomplished many of thethings I am proud of today. I would like to thank Gerald for all his support – a best friend in every sense of theword – and his daughter Keely for making me laugh. I would also like to thank Jen, Jocelyn, and Emily for theirsupport and being there for me. And as always I want to dedicate my work to my wife, Connie – without hersupport I would never have published a single word.

  • About the Code ConvertersUsually, Wrox books include biographies and dedications for the authors only. In this case, it wasdecided that the contribution that the code converters had made to this edition was sufficient that theyshould be included in this section.

    The authors of this book originally wrote all of the code in C#. Demian and Norbert did a great job ofconverting all of the code to Visual Basic .NET for this edition. The careful presentation andinformative commenting in the code show the dedication that they had to creating a useful resource forASP.NET developers who use VB.NET.

    Demian Martinez & Norbert MartinezDemian and Norbert have been messing with computers ever since their parents, also computerengineers, taught them to play games on their Apple II. In spite of being aeronautical engineers bydegree, they have devoted most of their careers to computing. Their combined working experience incompanies such as Gartner, PriceWaterhouseCoopers Consulting, British Airways, and Airbus has giventhem the opportunity to understand all phases of the software development lifecycle, from analysis toend-user training, through design, construction, and implementation.

    Demian and Norbert are currently working in No Red Inc., a small technology consulting companythey co-founded in Barcelona, Spain. They specialize in the development of web applications for small-to medium-sized companies using ASP.NET, VB.NET, and C#.

    AcknowledgementsDemian would like to thank his wife Mary for her support, her understanding, and her amazing smile. Norbertwould like to thank his partner Iratxe for her support, her love, and for not being too jealous when he spends sometime with the computer. Both Demian and Norbert would also like to thank their parents for being so special (andletting them play with the Apple II).

  • Table of Contents

    Introduction 1

    What Does This Book Cover? 1

    Who Is This Book For? 3

    What You Need to Use This Book 3

    Conventions 3

    Customer Support 4How to Download the Code for the Website 4Errata 4E-mail Support 5p2p.wrox.com 5

    Why This System Offers the Best Support 6

    Chapter 1: Building an ASP.NET Website 9

    The Problem 9

    The Design 10Working from Different Locations 10A Maintainable, Extendable Site 11Community 11Interesting Content 12Advertising 12Frequent Visits 12

    The Solution 13Working from Different Locations 13Building a Maintainable, Extendable Site 13Providing Interesting Content 13Managing Adverts 14Encouraging Community 14Getting Repeat Visitors 14Deploying the Site 14

    Summary 15

  • Table of Contents

    ii

    Chapter 2: Foundations 17

    The Problem 18The Problem Statement 19

    The Vision 19

    The Requirements 20

    The Design 20Naming and Coding Conventions 21

    Naming Guidelines 21

    Namespace Hierarchy 23Programming Language 27Folder Structure 27Designing the Database 28Building the Data-Services Tier 29Building the Business-Services Tier 30Error Handling and Fault Tolerance 32Deployment Issues 32User Interface Design 33

    The Solution 33The DbObject Class 34The BizObject Class 38The AppException Class 39

    Logging Events to a File 40

    Summary 42

    Chapter 3: Foundations for Style and Navigation 45

    The Problem 46The Problem Statement and Requirements 46

    The Design 47Cascading Stylesheets 48XSLT 50The Page Base Class 51A Reusable Navigation Control 51Headers and Footers 53Error Handling 54

    The Solution 54Styles 54The PhilePage Class 57The Navigator Control 58The SiteHeader Control 63The SiteFooter Control 65Error Handling 65Home Page Draft 68

    Summary 70

  • Table of Contents

    iii

    Chapter 4: Maintaining the Site 73

    The Problem 74FTP Versus Online File Management 74Database Management 75

    The Design 75Implementation Design 76Security Design 77

    The Solution 77Classes to Work with Files and Directories 78Header and Footer Controls 79The File Manager's Main Page 80

    Listing the Contents of a Folder 82

    Displaying Additional Attributes 87Downloading Files 99

    Uploading Files 102

    Creating Directories 105Creating Text Files 109

    Building the Text File Editor 111Editing Files 115

    Renaming Files and Directories 117Modifying the Attributes of Files and Directories 122

    Deleting Files 125

    Copying and Moving Files 129Securing the File Manager Using Windows Security 133

    Summary 136

    Chapter 5: Users and Authentication 139

    The Problem 139

    The Design 140Forms Authentication 141Designing the Database 142

    Stored Procedures 144The Data Tier 145The Business Tier 147

    The User Class 147The Role Class 148

    Extending .NET Framework User Handling 149Module Configuration 151

    The ModuleConfig Class 152The ModuleSettings Class 152

    Administration 153

    The Solution 153The Database 154

    Stored Procedures 155

  • Table of Contents

    iv

    The Data Tier 155User 156

    Role 163Permission 166

    PermissionCategory 169AccountsTool 170

    The Business Tier 171SitePrincipal 171SiteIdentity 174

    User 176

    Role 179AccountsTool 182

    Configuration Classes 183ModuleSettings 183ModuleConfig 183

    Modifying the UI to Support Authentication 185Modifying the SiteHeader Control 185The Login Page 186

    Picking up the Authentication Cookie in Subsequent Requests 187Configuring Forms Authentication 188

    Modifying the PhilePage Class 188

    The User Details Page 189Administering Roles and Accounts 191

    Summary 199

    Chapter 6: News Management 201

    The Problem 201

    The Design 202Features to Implement 203Database Design 203

    The News_Categories Table 204

    The News_News Table 205

    Stored Procedures 206Designing the Data Layer 208

    The CategoryDetails Class 209

    The Categories Class 209The NewsDetails Class 210

    The News Class 210Designing the Business Layer 211

    The Category Class 211

    The News Class 214Storing and Retrieving Settings 215Designing the Presentation Layer 216

    Plug-in Headlines 216

    The Headlines Web Service 216The Need for Security 217

  • Table of Contents

    v

    The Solution 218Working on the Database 218

    Relationships Between the Tables 218

    A Trigger for the UserID Foreign Key 221Creating the Stored Procedures 221

    Implementing the Data Access Assembly 226The News Class 226

    The Configuration Assembly 232The ModuleSettings Class 232

    The ModuleConfig Class 233

    The Settings File 235Implementing the Business Classes 235

    The News Class 235

    The Category Class 239The User Interface 240

    Administration 240Showing News to the User 267

    Showing the Categories 267Showing the Abstracts 269

    Showing the Whole News Item 270User-Submitted News 271The Headlines User Control 272

    Testing the Control 274Securing the Module 275The Headlines Web Service 277

    Testing the Web Service 278The News Ticker Application 280

    Summary 283

    Chapter 7: Advertising 287

    The Problem 287Impressions 287Hits 288Requirements 288

    Design 289Using the AdRotator 289The Database 290The Data Services Layer 292The Business Layer 293The Presentation Layer 293

    Advertising Administration 293Configuration 293

    The Solution 294The Database Tables 294

    AdsManager_Advertisements Table 294AdsManager_Companies Table 294

    AdsManager_Impressions Table 295

    AdsManager_Clicks Table 295

  • Table of Contents

    vi

    Stored Procedures 295The Data Services Layer 297

    The AdMaster Class 297The Advertisement Class 298

    The Business Layer 303The AdMaster Class 303The Advertisement Class 304

    The Presentation Layer 307The Pass-through Page 307The New SiteFooter Control 308

    Administering Advertisements 309Module Configuration 315

    Summary 316

    Chapter 8: Polls 319

    The Problem 319

    The Design 321Features to Implement 321

    Handling Multiple Votes 322Designing the Database Tables 324

    The Polls_Questions Table 324

    The Polls_Options Table 325

    The Polls_Votes Table 325The Stored Procedures that Manage the Database 326Designing the Data Layer 328

    The QuestionDetails Class 328

    The Questions Class 329The OptionDetails Class 329

    The Options Class 329The VoteDetails Class 330

    The Votes Class 330Storing and Retrieving Settings 330Designing the Business Layer 331

    The Question Class 331

    The Option Class 333Designing the User Interface Services 334

    The Poll User Control 334

    The Poll Web Service 336The Need for Security 337

    The Solution 337Working on the Database 337

    Creating the Relationships 338

    Creating the Stored Procedures 339Implementing the Data-Access Assembly 344The Configuration Assembly 344

    The ModuleSettings Class 344

    The ModuleConfig Class 345The Settings File 345

  • Table of Contents

    vii

    The Business Assembly 346The Question Class 346

    The Administration User Interface 351Creating the Header and Footer User Controls 352The Questions Manager Page 352

    The Questions.aspx Page 353

    The Code-behind for Questions.aspx 357Deleting a Question 360

    Creating a Question 360Managing the Options 361

    The Options.aspx Page 362

    The Code-behind File for Options.aspx 363Modifying the Settings Online 364

    The Settings.aspx Page 364

    The Code-behind for Settings.aspx 366The Poll User Control 367

    The Code-behind for the Poll User Control 369

    Handling the Postback Event 372

    Optimizing the Poll User Control 373Testing the Control 377

    The ShowArchive.aspx Page 381The Code-behind for ShowArchive.aspx 383

    Securing the Module 384The Poll Web Service 385

    Testing the Web Service 385

    The Windows Client Application 386

    Summary 389

    Chapter 9: Mailing Lists 393

    The Problem 393The Problem Statement 395

    The Design 396Designing the Database Tables 396

    The MLists_Lists Table 396The MLists_Users Table 397

    The MLists_Subscriptions Table 398The MLists_History Table 399

    The Stored Procedures that Manage the Database 399Designing the Data Services 402

    The ListDetails Class 402The Lists Class 402

    The SubscriptionDetails Class 403The Subscriptions Class 403

    The NewsletterDetails Class 403

    The Newsletters Class 403Storing and Retrieving Settings 404Designing the Business Services 405

    The List Class 405

    The Subscription Class 407

  • Table of Contents

    viii

    The Newsletter Class 408

    The Helper Class 409Designing the User Interface Services 410The Need for Security 411

    The Solution 411Working on the Database 411

    Creating the Stored Procedures and Triggers 411Implementing the Data and Configuration Assemblies 415Implementing the Business Layer 415

    The Subscription Class 415

    The Newsletter Class 419The Helper Class 423

    The Administration User Interface 425Sending out Newsletters to Subscribers 429Managing the Newsletters Archive 432

    Modifying the Settings Online 433Creating a Subscription Form for the User 434

    Subscribing to a Mailing List 438The Subscribe.aspx Page 440

    The Code-behind for Subscribe.aspx 440Securing the Module 441

    Summary 442

    Chapter 10: Forums and Online Communities 445

    The Problem 445Cross-Site Scripting 446

    The Design 446The Database 446

    The Forums_Categories Table 448The Forums_Forums Table 448

    The Forums_Topics Table 449

    The Forums_Replies Table 450The Forums_Members Table 451

    Database Views 451Stored Procedures 452

    Designing the Data Services 454Configuration 454The Business Layer 455

    The Forum Class 455The Helper Class 456

    Designing the User Interface Layer 456

    The Solution 457Creating the Database Tables 458

    Creating the Views 458

    Creating the Stored Procedures 461Implementing the Data Layer 463Implementing the Configuration Layer 463

  • Table of Contents

    ix

    Implementing the Business Layer 464The Forum Class 464

    The Helper Class 468The Presentation Layer 471

    The Categories and Forums Page 471

    The Header Control 481

    The Forum.aspx Page 483The Topic.aspx Page 489

    The PostMessage.aspx Page 496The MyProfile.aspx Page 503

    Summary 505

    Chapter 11: Deploying the Site 509

    The Problem 510

    The Design 510Deploying the Data Store 510Preparing the Site for Deployment 511Manual (XCopy) Deployment 513

    Configuring IIS for your Application 513Deploying to a Hosting Service 514Automated Deployment (Building Installers) 515

    The Solution 515

    Summary 519

    Chapter 12: The End 521

    Get Building 521

    Join Our Community 521

    Read More 522Web Services 522Security 522ADO.NET 522Server Controls 522

    Index 525

  • Introduction

    Welcome to ASP.NET Website Programming. In this book we will build an interactive, content-basedwebsite using expandable, interchangeable modules. By the end of the book you will have developedyour ASP.NET skills for producing effective, well-engineered, extendable websites.

    ASP.NET is a great tool for building websites. It contains many built-in features that would takethousands of lines of code in classic ASP, and it does not require admin rights in order to deploycompiled components – your whole site can be deployed in one folder.

    This book will guide you through the bewildering features available to ASP.NET developers,highlighting the most useful and exciting.

    The book concentrates on websites that focus on content. It does not show how to produce an e-commerce system, although a lot of the advice will apply to e-commerce sites. We could add a shoppingbasket module using the same foundations, for example.

    This book is different from most Wrox books, because we build a single working website throughout thebook. However, each chapter stands alone and shows how to develop individual modules, which youcan adapt for your own websites. We also suggest a framework that allows us to create modules and slotthem in to the website quickly and easily.

    What Does This Book Cover?The chapters in this book follow a problem-design-solution pattern. First we identify what we need toachieve, then we sketch out how we will achieve it, and finally we build the software in Visual Studio .NET.

    Most chapters involve building a 3-tier system, with data, business, and presentation layers. We will alsosee how to build separate modules so that they integrate well into the whole site.

  • Introduction

    2

    Chapter 1 looks at the website as a whole. We identify the problem that it is trying to solve, and discusshow we will go about solving it. We then come up with a solution – which involves building andintegrating the modules detailed in the other chapters.

    Chapter 2 builds the foundations of our site. We set coding standards and design our folder andnamespace structure. We create our initial database – although at this stage we have no data to put in it.We also build site-wide error handling code and base classes for our data and business layer objects.

    Chapter 3 extends our foundations to the presentation layer. We build base classes for the ASP.NETpages in the site, a custom error page, and site-wide navigation, header, and footer controls.

    Chapter 4 presents a file management module, which we can use to download and upload source codefor the site, and make changes online. We will also look at Microsoft's Data Manager, which enables usto manage SQL Server databases through our website.

    Chapter 5 covers user accounts. We look at how to create a powerful role-based security system, andintegrate it with ASP.NET's built-in authentication features.

    Chapter 6 shows how to provide regularly changing news content through a website. We also build aweb service to expose news headlines to other sites and applications, and a Windows news ticker thatuses this web service.

    Chapter 7 looks at advertising. We create our advertising system by extending the ASP.NETAdRotator control to provide the power we need. We look at logging hits and impressions, andproviding reports to advertisers.

    Chapter 8 covers opinion polls and voting. We look at how to administer questions, log votes, andcollate them into useful reports.

    Chapter 9 provides the tools to create e-mail newsletters. We will look at how to create messages inplain text and HTML, and how to administer lists and set up new ones.

    Chapter 10 looks at forums. We create everything you need to post and read messages, and giveadministrators special permissions. Along the way, there is some powerful use of the DataList andDataGrid controls. We also look at how to use regular expressions to provide limited HTML support,without opening our forum to the risk of cross-site scripting.

    Chapter 11 shows how to deploy the site. We will look at the ways Visual Studio .NET allows us to providesource-free distributable versions of our software, and how to deploy our sites onto hosting services.

    Chapter 12 looks to the future. We've only just begun our lives as ASP.NET website developers andhere we will look at ways in which Wrox can support your continued development. In particular thisincludes the book's P2P list, where you can work together with fellow readers and benefit from eachother's ideas and experience.

  • Introduction

    3

    Who Is This Book For?The book is for developers who have a reasonable knowledge of ASP.NET, and want to apply thatknowledge to building websites. You will get the most from this book if you have read a decent amountof Wrox's Beginning ASP.NET using Visual Basic .NET, or Professional ASP.NET and a VB.NET book.

    You should be comfortable using Visual Studio .NET to create ASP.NET projects, and that youknow VB.NET.

    What You Need to Use This BookTo run the code samples in this book you need to have the following:

    ❑ Windows 2000 or Windows XP.

    ❑ Visual Studio .NET 1.0. We have tested the code for version 1.0, although most of the codeshould work in late pre-release versions. Nearly everything will also work in Visual Basic.NET Standard.

    ❑ SQL Server 2000 – although most of the techniques we use could apply to any databasesystem, including Access.

    To get the site working you may also need an ASP.NET web host. We will give some guidance onchoosing one towards the end of the book.

    ConventionsWe've used a number of different styles of text and layout in this book to help differentiate between thedifferent kinds of information. Here are examples of the styles we used and an explanation of whatthey mean.

    Code has several styles. If it's a word that we're talking about in the text – for example, when discussinga For...Next loop, it's in this font. If it's a block of code that can be typed as a program and run, thenit's also in a gray box:

    Sometimes we'll see code in a mixture of styles, like this:

    Widget $10.00

    In cases like this, the code with a white background is code we are already familiar with; the linehighlighted in gray is a new addition to the code since we last looked at it.

  • Introduction

    4

    Advice, hints, and background information comes in this type of font.

    Important pieces of information come in boxes like this.

    Bullets appear indented, with each new bullet marked as follows:

    ❑ Important Words are in a bold type font.

    ❑ Words that appear on the screen, or in menus like File or Window, are in a similar font to theone you would see on a Windows desktop.

    ❑ Keys that you press on the keyboard, such as Ctrl and Enter, are in italics.

    Customer SupportWe want to hear from you! We want to know what you think about this book: what you liked, what youdidn't like, and what you think we can do better next time. Please send us your comments, either byreturning the reply card in the back of the book, or by e-mailing [email protected]. Please mentionthe book title in your message.

    We do listen to these comments, and we do take them into account on future books.

    How to Download the Code for the WebsiteIt is well worth getting the website working on your own machine before reading too much of this book.It will help you follow the descriptions, because you will be able to see how code snippets relate to thewhole application, and experience the modular approach first hand.

    To get the code, visit www.wrox.com and navigate to ASP.NET Website Programming Visual Basic .NETEdition. Click on Download in the Code column, or on Download Code on the book's detail page.

    The files are in ZIP format. Windows XP recognizes these automatically, but Windows 2000 requires ade-compression program such as WinZip or PKUnzip. The archive contains the whole site, plus areadme describing how to get it up and running.

    ErrataWe've made every effort to make sure that there are no errors in the text or in the code. If you do findan error, such as a spelling mistake, faulty piece of code, or any inaccuracy, we would appreciatefeedback. By sending in errata you may save another reader hours of frustration, and help us provideeven higher quality information.

    E-mail your comments to [email protected]. Your information will be checked and if correct, postedto the errata page for that title, and used in subsequent editions of the book.

    To find errata for this title, go to www.wrox.com and locate ASP.NET Website Programming Visual Basic.NET Edition. Click on the Book Errata link, which is below the cover graphic on the book's detail page.

  • Introduction

    5

    E-mail SupportIf you wish to directly query a problem in the book with an expert who knows the book in detail then e-mail [email protected], with the title of the book and the last four numbers of the ISBN in the subjectfield of the e-mail. Please include the following things in your e-mail:

    ❑ The title of the book, last four digits of the ISBN (8163), and page number of the problem inthe Subject field.

    ❑ Your name, contact information, and the problem in the body of the message.

    We won't send you junk mail. We need the details to save your time and ours. When you send an e-mailmessage, it will go through the following chain of support:

    ❑ Customer Support – Your message is delivered to our customer support staff, who are the firstpeople to read it. They have files on most frequently asked questions and will answer anythinggeneral about the book or the website immediately.

    ❑ Editorial – Deeper queries are forwarded to the technical editor responsible for that book.They have experience with the programming language or particular product, and are able toanswer detailed technical questions on the subject.

    ❑ The Authors – If even the editor cannot answer your problem, they will forward the request tothe author. We do try to protect the author from any distractions to their writing, but we arehappy to forward specific requests to them. All Wrox authors help with the support on theirbooks. They will e-mail the customer and the editor with their response, and again all readersshould benefit.

    The Wrox Support process can only offer support to issues that directly relate to the content of thebook. Support for questions that fall outside the scope of normal book support is provided via thecommunity lists of our http://p2p.wrox.com/ forum.

    p2p.wrox.comFor author and peer discussion join the P2P mailing lists. Our unique system provides programmer toprogrammer™ contact on mailing lists, forums, and newsgroups, all in addition to our one-to-one e-mailsupport system. If you post a query to P2P, you can be confident that the many Wrox authors and industryexperts who use our mailing lists will examine it. At p2p.wrox.com you will find a number of different liststhat will help you, not only while you read this book, but also as you develop your own applications.

    This book has its own list called aspdotnet_website_programming. Using this, you can talk to otherpeople who are developing websites using the methods and framework presented here. You can shareideas and code for new and improved modules, get help with programming headaches, and show off thesites you've written!

  • Introduction

    6

    To subscribe to a mailing list just follow these steps:

    1. Go to http://p2p.wrox.com/.

    2. Choose the appropriate category from the left menu bar.

    3. Click on the mailing list you wish to join.

    4. Follow the instructions to subscribe and fill in your e-mail address and password.

    5. Reply to the confirmation e-mail you receive.

    6. Use the subscription manager to join more lists and set your e-mail preferences.

    Why This System Offers the Best SupportYou can choose to join the mailing lists or you can receive them as a weekly digest. If you don't havethe time, or facility, to receive the mailing list, then you can search our online archives. Junk and spammails are deleted, and the unique Lyris system protects your e-mail address. Queries about joining orleaving lists, and any other general queries about lists, should be sent to [email protected].

  • Introduction

    7

  • Building an ASP.NET Website

    In this book we are going to build a content-based ASP.NET website. This website will consist of anumber of modules, which will all fit together to produce the finished product.

    We will build each module in a standard order:

    ❑ Identify the problem – What do we want to do? What restrictions or other factors do we needto take into account?

    ❑ Produce a design – Decide what features we need to solve the problem. Get a broad idea ofhow the solution will work.

    ❑ Build the solution – Produce the code, and any other material, that will realize the design.

    This book focuses on programming. When we talk about design, we generally mean designing thesoftware – we will not be looking at graphic or user interface design.

    Your website will not be solving all of the same problems as ours, but many of the modules we build –and the programming techniques we use – are very transferable.

    In this chapter we will take a high-level look at the whole site – what it needs to do, and how it will do it.

    The ProblemWe will be building a website for DVD and book enthusiasts. In outlining the site's problem, we need toconsider the purpose and audience. In real life this stage would be business oriented – taking intoaccount things like advertising demographics, competition, and availability of funding. These processesneed to be analyzed rigorously, but we will leave all that to the managers.

    1

  • Chapter 1

    10

    Our site will cater for lovers of books and DVDs. It will provide useful content and try to build community.Our visitors will want to read about these things, and contribute their opinions, but each visit will be fairlyshort – this will not be a huge database in the style of the Internet Movie Database (www.imdb.com). It willbe funded by advertising, and will rely on repeated (but fairly short) visits from its readers.

    We also need to consider constraints. These are more practical. One of the major constraints that thissite faced was the development team – the members would never meet, because they were on oppositesides of the world. This meant that the design must allow one developer to work on sections of the sitewithout interfering with other developers working on different sections. But all of the sections needed toeventually work together smoothly. In most cases the separation between developers will be lessextreme, but giving each developer the ability to work independently is very useful. We need to designand build methods to enable this.

    Site development never really finishes – sites tend to be tweaked frequently. Another key to successfulwebsites is to design them in a way that makes modification easy. We will need to find ways to do this.

    We will call our site ThePhile.com, because it is a site for lovers of books (bibliophiles)and DVDs (DVD-philes). It's also a play on the word 'file', because our website will bea definitive source of information.

    The DesignWe have outlined what our site needs – now let's look at how we can provide it. The main points raisedin the problem section were:

    ❑ Enable developers to work from many different locations

    ❑ Build a maintainable, extendable site

    ❑ Build community

    ❑ Provide interesting content

    ❑ Provide revenue through advertising

    ❑ Encourage frequent visits

    Let's discuss each of these in turn.

    Working from Different LocationsOur developers need to work on sections of the site with relatively little communication. Ourdevelopers are in different countries so face-to-face meetings are impossible. Telephone conversationscan be expensive, and different time zones cause problems.

    We need to design the system so that developers can work on their own section of the site, knowing thatthey will not damage the work of others.