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 4
How to Download the Code for the Website 4
Errata 4
E-mail Support 5
p2p.wrox.com 5
Why This System Offers the Best Support 6
Chapter 1: Building an ASP.NET Website
9
The Problem 9
The Design 10
Working from Different Locations 10
A Maintainable, Extendable Site 11
Community 11
Interesting Content 12
Advertising 12
Frequent Visits 12
The Solution 13
Working from Different Locations 13
Building a Maintainable, Extendable Site 13
Providing Interesting Content 13
Managing Adverts 14
Encouraging Community 14
Getting Repeat Visitors 14
Deploying the Site 14
Summary 15
Chapter 2: Foundations
17
The Problem 18
The Problem Statement 19
The Vision 19
The Requirements 20
The Design 20
Naming and Coding Conventions 21
Naming Guidelines 21
Namespace Hierarchy 23
Programming Language 27
Folder Structure 27
Designing the Database 28
Building the Data-Services Tier 29
Building the Business-Services Tier 30
Error Handling and Fault Tolerance 32
Deployment Issues 32
User Interface Design 33
The Solution 33
The DbObject Class 34
The BizObject Class 38
The AppException Class 39
Logging Events to a File 40
Summary 42
Chapter 3: Foundations for Style and Navigation
45
The Problem 46
The Problem Statement and Requirements 46
The Design 47
Cascading Stylesheets 48
XSLT 50
The Page Base Class 51
A Reusable Navigation Control 51
Headers and Footers 53
Error Handling 54
The Solution 54
Styles 54
The PhilePage Class 57
The Navigator Control 58
The SiteHeader Control 63
The SiteFooter Control 65
Error Handling 65
Home Page Draft 68
Summary 70
Chapter 4: Maintaining the Site
73
The Problem 74
FTP Versus Online File Management 74
Database Management 75
The Design 75
Implementation Design 76
Security Design 77
The Solution 77
Classes to Work with Files and Directories 78
Header and Footer Controls 79
The File Manager's Main Page 80
Listing the Contents of a Folder 82
Displaying Additional Attributes 87
Downloading Files 99
Uploading Files 102
Creating Directories 105
Creating Text Files 109
Building the Text File Editor 111
Editing Files 115
Renaming Files and Directories 117
Modifying the Attributes of Files and Directories 122
Deleting Files 125
Copying and Moving Files 129
Securing the File Manager Using Windows Security 133
Summary 136
Chapter 5: Users and Authentication
139
The Problem 139
The Design 140
Forms Authentication 141
Designing the Database 142
Stored Procedures 144
The Data Tier 145
The Business Tier 147
The User Class 147
The Role Class 148
Extending .NET Framework User Handling 149
Module Configuration 151
The ModuleConfig Class 152
The ModuleSettings Class 152
Administration 153
The Solution 153
The Database 154
Stored Procedures 155
The Data Tier 155
User 156
Role 163
Permission 166
PermissionCategory 169
AccountsTool 170
The Business Tier 171
SitePrincipal 171
SiteIdentity 174
User 176
Role 179
AccountsTool 182
Configuration Classes 183
ModuleSettings 183
ModuleConfig 183
Modifying the UI to Support Authentication 185
Modifying the SiteHeader Control 185
The Login Page 186
Picking up the Authentication Cookie in Subsequent Requests 187
Configuring Forms Authentication 188
Modifying the PhilePage Class 188
The User Details Page 189
Administering Roles and Accounts 191
Summary 199
Chapter 6: News Management
201
The Problem 201
The Design 202
Features to Implement 203
Database Design 203
The News--Categories Table 204
The News--News Table 205
Stored Procedures 206
Designing the Data Layer 208
The CategoryDetails Class 209
The Categories Class 209
The NewsDetails Class 210
The News Class 210
Designing the Business Layer 211
The Category Class 211
The News Class 214
Storing and Retrieving Settings 215
Designing the Presentation Layer 216
Plug-in Headlines 216
The Headlines Web Service 216
The Need for Security 217
The Solution 218
Working on the Database 218
Relationships Between the Tables 218
A Trigger for the UserID Foreign Key 221
Creating the Stored Procedures 221
Implementing the Data Access Assembly 226
The News Class 226
The Configuration Assembly 232
The ModuleSettings Class 232
The ModuleConfig Class 233
The Settings File 235
Implementing the Business Classes 235
The News Class 235
The Category Class 239
The User Interface 240
Administration 240
Showing News to the User 267
Showing the Categories 267
Showing the Abstracts 269
Showing the Whole News Item 270
User-Submitted News 271
The Headlines User Control 272
Testing the Control 274
Securing the Module 275
The Headlines Web Service 277
Testing the Web Service 278
The News Ticker Application 280
Summary 283
Chapter 7: Advertising
287
The Problem 287
Impressions 287
Hits 288
Requirements 288
Design 289
Using the AdRotator 289
The Database 290
The Data Services Layer 292
The Business Layer 293
The Presentation Layer 293
Advertising Administration 293
Configuration 293
The Solution 294
The Database Tables 294
AdsManager--Advertisements Table 294
AdsManager--Companies Table 294
AdsManager--Impressions Table 295
AdsManager--Clicks Table 295
Stored Procedures 295
The Data Services Layer 297
The AdMaster Class 297
The Advertisement Class 298
The Business Layer 303
The AdMaster Class 303
The Advertisement Class 304
The Presentation Layer 307
The Pass-through Page 307
The New SiteFooter Control 308
Administering Advertisements 309
Module Configuration 315
Summary 316
Chapter 8: Polls
319
The Problem 319
The Design 321
Features to Implement 321
Handling Multiple Votes 322
Designing the Database Tables 324
The Polls--Questions Table 324
The Polls--Options Table 325
The Polls--Votes Table 325
The Stored Procedures that Manage the Database 326
Designing the Data Layer 328
The QuestionDetails Class 328
The Questions Class 329
The OptionDetails Class 329
The Options Class 329
The VoteDetails Class 330
The Votes Class 330
Storing and Retrieving Settings 330
Designing the Business Layer 331
The Question Class 331
The Option Class 333
Designing the User Interface Services 334
The Poll User Control 334
The Poll Web Service 336
The Need for Security 337
The Solution 337
Working on the Database 337
Creating the Relationships 338
Creating the Stored Procedures 339
Implementing the Data-Access Assembly 344
The Configuration Assembly 344
The ModuleSettings Class 344
The ModuleConfig Class 345
The Settings File 345
The Business Assembly 346
The Question Class 346
The Administration User Interface 351
Creating the Header and Footer User Controls 352
The Questions Manager Page 352
The Questions.aspx Page 353
The Code-behind for Questions.aspx 357
Deleting a Question 360
Creating a Question 360
Managing the Options 361
The Options.aspx Page 362
The Code-behind File for Options.aspx 363
Modifying the Settings Online 364
The Settings.aspx Page 364
The Code-behind for Settings.aspx 366
The Poll User Control 367
The Code-behind for the Poll User Control 369
Handling the Postback Event 372
Optimizing the Poll User Control 373
Testing the Control 377
The ShowArchive.aspx Page 381
The Code-behind for ShowArchive.aspx 383
Securing the Module 384
The Poll Web Service 385
Testing the Web Service 385
The Windows Client Application 386
Summary 389
Chapter 9: Mailing Lists
393
The Problem 393
The Problem Statement 395
The Design 396
Designing the Database Tables 396
The MLists--Lists Table 396
The MLists--Users Table 397
The MLists--Subscriptions Table 398
The MLists--History Table 399
The Stored Procedures that Manage the Database 399
Designing the Data Services 402
The ListDetails Class 402
The Lists Class 402
The SubscriptionDetails Class 403
The Subscriptions Class 403
The NewsletterDetails Class 403
The Newsletters Class 403
Storing and Retrieving Settings 404
Designing the Business Services 405
The List Class 405
The Subscription Class 407
The Newsletter Class 408
The Helper Class 409
Designing the User Interface Services 410
The Need for Security 411
The Solution 411
Working on the Database 411
Creating the Stored Procedures and Triggers 411
Implementing the Data and Configuration Assemblies 415
Implementing the Business Layer 415
The Subscription Class 415
The Newsletter Class 419
The Helper Class 423
The Administration User Interface 425
Sending out Newsletters to Subscribers 429
Managing the Newsletters Archive 432
Modifying the Settings Online 433
Creating a Subscription Form for the User 434
Subscribing to a Mailing List 438
The Subscribe.aspx Page 440
The Code-behind for Subscribe.aspx 440
Securing the Module 441
Summary 442
Chapter 10: Forums and Online Communities
445
The Problem 445
Cross-Site Scripting 446
The Design 446
The Database 446
The Forums--Categories Table 448
The Forums--Forums Table 448
The Forums--Topics Table 449
The Forums--Replies Table 450
The Forums--Members Table 451
Database Views 451
Stored Procedures 452
Designing the Data Services 454
Configuration 454
The Business Layer 455
The Forum Class 455
The Helper Class 456
Designing the User Interface Layer 456
The Solution 457
Creating the Database Tables 458
Creating the Views 458
Creating the Stored Procedures 461
Implementing the Data Layer 463
Implementing the Configuration Layer 463
Implementing the Business Layer 464
The Forum Class 464
The Helper Class 468
The Presentation Layer 471
The Categories and Forums Page 471
The Header Control 481
The Forum.aspx Page 483
The Topic.aspx Page 489
The PostMessage.aspx Page 496
The MyProfile.aspx Page 503
Summary 505
Chapter 11: Deploying the Site
509
The Problem 510
The Design 510
Deploying the Data Store 510
Preparing the Site for Deployment 511
Manual (XCopy) Deployment 513
Configuring IIS for your Application 513
Deploying to a Hosting Service 514
Automated Deployment (Building Installers) 515
The Solution 515
Summary 519
Chapter 12: The End
521
Get Building 521
Join Our Community 521
Read More 522
Web Services 522
Security 522
ADO.NET 522
Server Controls 522
Index
525