ebook img

ASP 2005 after hours : 10 projects you'll never do at work PDF

374 Pages·2005·1.753 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview ASP 2005 after hours : 10 projects you'll never do at work

00 0672326477 fm 4/29/04 9:49 AM Page i Dan Kent ASP NET . E V O L U T I O N 800 East 96th Street,Indianapolis,Indiana 46240 00 0672326477 fm 4/29/04 9:49 AM Page ii ASP.NET Evolution Associate Publisher Michael Stephens Copyright © 2004 by Sams Publishing All rights reserved. No part of this book shall be reproduced, stored in a Acquisitions Editor retrieval system, or transmitted by any means, electronic, mechanical, photo- Neil Rowe copying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the infor- Development Editor mation contained herein. Although every precaution has been taken in the Mark Renfrow preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting Managing Editor from the use of the information contained herein. Charlotte Clapp International Standard Book Number: 0-672-32647-7 Project Editor Library of Congress Catalog Card Number: 2004091250 Tonya Simpson Printed in the United States of America Copy Editor First Printing: June 2004 Jessica McCarty 07 06 05 04 4 3 2 1 Indexer Trademarks Mandie Frank All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams Publishing cannot attest to Proofreader the accuracy of this information. Use of a term in this book should not be Tonya Fenimore regarded as affecting the validity of any trademark or service mark. Technical Editor Warning and Disclaimer Doug Holland Every effort has been made to make this book as complete and as accurate as Publishing Coordinator possible, but no warranty or fitness is implied. The information provided is on an “as is” basis. The author and the publisher shall have neither liability Cindy Teeters nor responsibility to any person or entity with respect to any loss or damages Multimedia Developer arising from the information contained in this book or from the use of the CD or programs accompanying it. Dan Scherf Bulk Sales Book Designer Gary Adair Sams Publishing offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales. For more information, please contact U.S. Corporate and Government Sales 1-800-382-3419 [email protected] For sales outside of the U.S., please contact International Sales 1-317-428-3341 [email protected] 00 0672326477 fm 4/29/04 9:49 AM Page iii Contents at a Glance Introduction..................................................................................1 1 Getting Started..............................................................................3 2 The Online Community Application....................................................11 3 Exploring the Code........................................................................25 4 Experimenting with the Code...........................................................69 5 Improving the User Interface............................................................91 6 Improving the Modules.................................................................135 7 Managing Members.....................................................................169 8 Keeping Members Under Control....................................................207 9 Improving the Code.....................................................................247 10 Extending the Application..............................................................295 Index.......................................................................................345 00 0672326477 fm 4/29/04 9:49 AM Page iv Table of Contents Introduction 1 1 Getting Started 3 What You Need to Run the Application.........................................................3 Versions of the Application on the CD-ROM...........................................4 STEP-BY-STEP GUIDE: Installing the Application.................................4 Copying the Source Code Files ..........................................................4 STEP-BY-STEP GUIDE: Setting Up the Web Application.........................5 STEP-BY-STEP GUIDE: Compiling the Source Code..............................6 Setting Up the Database..................................................................7 Checking the Application Configuration................................................8 Copying the WebControl Client Script Files............................................9 Testing the Application.....................................................................9 Troubleshooting.....................................................................................9 Access Is Denied Microsoft.Web.UI.WebControls..........................9 Directory Not Found Exception for C:\Inetpub\wwwroot\community\ global\OJB.NET\repository.xml.............................................9 SQL Server Does Not Exist or Access Denied......................................10 Could Not Load Type......................................................................10 Moving On..........................................................................................10 2 The Online Community Application 11 What Does the Online Community Application Do?........................................11 Members....................................................................................13 Modules.....................................................................................14 Global Module Instances................................................................16 Adding Information to Module Instances.............................................18 Member Settings..........................................................................19 Search.......................................................................................22 Moving On..........................................................................................23 00 0672326477 fm 4/29/04 9:49 AM Page v 3 Exploring the Code 25 Terminology.........................................................................................25 Why Was the Online Community Built the Way It Was?...................................26 The Overall Logical Structure...................................................................27 ASP.NET Pages.............................................................................27 Controls.....................................................................................28 Business Services........................................................................28 Persistent Objects........................................................................29 Member.....................................................................................30 CommunityModule......................................................................31 ModuleView..............................................................................32 ModuleInstance.......................................................................33 SectionItem.............................................................................34 Section....................................................................................34 The Persistence Service.................................................................35 The Database......................................................................................36 The Modules.......................................................................................37 The ModuleBaseClass.................................................................37 How the Code Files Are Organized............................................................38 CODE TOUR: Default.aspx.......................................................40 CODE TOUR: CoreModule.vb.....................................................47 CODE TOUR: DisplayLatestHeadlines.ascx.............................55 CODE TOUR: NewsModule.vb.....................................................57 Search...............................................................................................60 Security.............................................................................................66 Moving On..........................................................................................67 4 Experimenting with the Code 69 Changing the Style of the Application........................................................69 EXPERIMENT: Playing with the Style Sheet......................................69 CODE TOUR: Navigation.ascx..................................................77 STEP-BY-STEP GUIDE: Adding Icons to the Navigation........................86 Moving On..........................................................................................89 00 0672326477 fm 4/29/04 9:49 AM Page vi vi ASP.NET Evolution 5 Improving the User Interface 91 Section Items......................................................................................91 CODE TOUR: Global/Controls/SectionItemHeader.ascx..........91 STEP-BY-STEP GUIDE: Adding the Number of Images to the Header of ImageGalleryModule Instances....................................94 CHALLENGE: Displaying the Number of Images for Global Instances......95 IDEA: Customizing the Header for Other Modules.............................95 STEP-BY-STEP GUIDE: Adding Icons to Module Headers.....................96 CHALLENGE: Distinguishing Global Instances..................................99 STEP-BY-STEP GUIDE: Adding a New Icon to Module Instances That Have Been Updated in the Last Week........................................99 STEP-BY-STEP GUIDE: Adding New Icons to the Navigation................103 STEP-BY-STEP GUIDE: Adding an Automated What’s New? Page..........108 CHALLENGE: Showing Only Non-global Sections in What’s New?.........115 STEP-BY-STEP GUIDE: Displaying the Latest Member to Join..............115 STEP-BY-STEP GUIDE: Allowing Members to Have a Custom Image on Their Page...........................................................................119 CHALLENGE: Imposing a Size Limit on Uploaded Images..................126 STEP-BY-STEP GUIDE: Adding Configurable Module Names................126 CHALLENGE: Display Names for Module Views...............................132 STEP-BY-STEP GUIDE: Solving a Problem with the Return Key.............132 CHALLENGE: Adding Default Buttons to Other Controls.....................134 Moving On........................................................................................134 6 Improving the Modules 135 The Send Message Module...................................................................135 CODE TOUR: SendMessageModule.vb.......................................135 CODE TOUR: Modules/SendMessage/ SimpleSendMessageBox.ascx.................................................137 STEP-BY-STEP GUIDE: Requiring a Valid Email Address.....................139 CHALLENGE: Requiring a Valid Email Address from New Members......142 STEP-BY-STEP GUIDE: Dealing with Errors.....................................142 STEP-BY-STEP GUIDE: Allowing a Global SendMessageInstance........145 CHALLENGE: User-Definable Subject Line......................................148 00 0672326477 fm 4/29/04 9:49 AM Page vii Contents vii The News Module...............................................................................148 CODE TOUR: Modules/News/DisplayItem.ascx .......................149 STEP-BY-STEP GUIDE: Formatting News Items Better.......................152 Entering and Editing News Items............................................................155 STEP-BY-STEP GUIDE: Validating the Length of the Inputs.................157 CHALLENGE: Automatic Summaries.............................................158 STEP-BY-STEP GUIDE: Allowing Markup Code.................................159 CHALLENGE: Adding More Markup Options....................................162 CHALLENGE: Allowing Members to Upload an Image to Accompany Each News Item .......................................................................162 The ImageGallery Module.....................................................................163 STEP-BY-STEP GUIDE: Generating Thumbnails................................163 Moving On........................................................................................167 7 Managing Members 169 Building a Member Administration System................................................169 Protecting the Administration System...............................................169 CODE TOUR: Global/CommunityPrincipal.vb.........................171 STEP-BY-STEP GUIDE: Adding General Member Management Facilities.................................................................................172 Helping Users Who Forget Their Passwords...............................................189 STEP-BY-STEP GUIDE: Automating Password Resetting.....................190 CHALLENGE: One-Use-Only Change Password Emails.......................197 Improving the Registration Process.........................................................198 STEP-BY-STEP GUIDE: Requiring Approval for New User Registrations...........................................................................198 CHALLENGE: Email Reminders...................................................205 CHALLENGE: Requiring Email Confirmation for Registration...............205 IDEA: Requiring Agreement to Terms and Conditions........................205 Moving On........................................................................................206 00 0672326477 fm 4/29/04 9:49 AM Page viii viii ASP.NET Evolution 8 Keeping Members Under Control 207 Managing Members’ Resource Usage......................................................207 STEP-BY-STEP GUIDE: Setting a Quota for Members’ Data................207 CHALLENGE: Including the Member’s Personal Page Image and Text in Her Resource Usage...................................................223 IDEA: Personalized Resource Quotas...........................................223 Dealing with Troublesome Users.............................................................224 STEP-BY-STEP GUIDE: Temporarily Banning a Member......................224 STEP-BY-STEP GUIDE: Hiding Deactivated Members’ Data.................226 STEP-BY-STEP GUIDE: Deleting a Member.....................................228 STEP-BY-STEP GUIDE: Logging IP Addresses..................................233 CHALLENGE: Updating the Date on Existing IP Addresses.................240 Security Configuration Options...............................................................241 STEP-BY-STEP GUIDE: Changing the Timeout Period.........................241 STEP-BY-STEP GUIDE: Remembering Members Between Visits...........241 STEP-BY-STEP GUIDE: Building a Private Community........................243 Moving On........................................................................................246 9 Improving the Code 247 Improving Performance with Caching........................................................247 STEP-BY-STEP GUIDE: Caching Page Output...................................248 STEP-BY-STEP GUIDE: Partial-Page Caching...................................250 CHALLENGE: Caching a Dynamic Control.......................................251 Viewstate.........................................................................................251 STEP-BY-STEP GUIDE: Pruning the Viewstate .................................252 Improving Text-Handling Performance with StringBuilder.........................253 Eliminating Magic Numbers...................................................................260 STEP-BY-STEP GUIDE: Making the Thumbnail Width Configurable........264 STEP-BY-STEP GUIDE: Removing the Community.RandomTextItem Duplication..............................................................................269 CHALLENGE: Removing the Type.GetTypeDuplication in All Module Classes..................................................................................270 Reorganizing Code......................................................................271 00 0672326477 fm 4/29/04 9:49 AM Page ix Contents ix STEP-BY-STEP: Breaking Out Databinding Code into a Databinding Subroutine..............................................................................278 CHALLENGE: Breaking Out Databinding Code.................................279 Creating Reusable Code.......................................................................279 More Efficient Data Access...................................................................281 STEP-BY-STEP GUIDE: Using Custom SQL to Get Recent News Items...283 Retrieving Less Data with Summary Objects..............................................285 STEP-BY-STEP GUIDE: Using a NewsItemSummaryClass.................286 CHALLENGE: Implementing Another Summary Class........................291 Improving File Naming..........................................................................292 Moving On........................................................................................294 10 Extending the Application 295 Adding a New View..............................................................................295 CHALLENGE: Improving the DisplaySingleImageView.................299 Adding a New Module..........................................................................299 Required Items...........................................................................299 Optional Items...........................................................................300 STEP-BY-STEP GUIDE: Implementing the Persistent Object................300 STEP-BY-STEP GUIDE: Creating a Business Service Class for the Module...................................................................................306 STEP-BY-STEP GUIDE: Implementing the Display Module Control.........314 STEP-BY-STEP GUIDE: Implementing a View to Display Upcoming Events....................................................................................318 STEP-BY-STEP GUIDE: Adding a View to Display a Graphical Calendar.................................................................................320 STEP-BY-STEP GUIDE: Implementing the View Item Control................326 Making the Calendar Module Work..................................................331 CHALLENGE: Adding a Delete Event Option ...................................333 CHALLENGE: Displaying an Error Message....................................333 Integrating ASP.NET Forums with the Online Community Application.................334 STEP-BY-STEP GUIDE: Integrating ASP.NET Forums..........................334 Moving On........................................................................................342 Index 345

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.