Real-World ASP.NET: Building a Content Management System978-1-4302-0832-7/1.pdf · Real-World...

16
Real-World ASP.NET: Building a Content Management System STEPHEN R. G. FRASER APress Media, LLC

Transcript of Real-World ASP.NET: Building a Content Management System978-1-4302-0832-7/1.pdf · Real-World...

Real-World ASP.NET: Building a Content Management System

STEPHEN R. G. FRASER

APress Media, LLC

Real-World ASP.NET: Building a Content Management System Copyright© 2002 by Stephen R. G. Fraser Originally published by Apress in 2002

All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.

ISBN 978-1-59059-024-9 ISBN 978-1-4302-0832-7 (eBook) DOI 10.1007/978-1-4302-0832-7

Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.

Editorial Directors: Dan Appleman, Peter Blackburn, Gary Cornell, Iason Gilmore, Karen Watterson, John Zukowski Managing Editor: Grace Wong Copy Editor: Nicole LeClerc Production Editor: JanetVail Compositor: Impressions Artist: Kurt Krames Indexer: Rebecca Plunkett Cover Designer: Tom Debolski Marketing Manager: Stephanie Rodriguez

For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710. E-mail info@apress. corn, or visit http: 1 /www. apress. corn.

The information in this book is distributed on an "as is" hasis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work.

To my energy, Sarah, and bundle ofjoy, Shaina, with love.

Contents at a Glance

About the Author ................................................... . xiii

Introduction ......................................................... . xv

Chapter 1 So, What Is a Content Management System Anyway? 1

• • • • • 2 9

.41

Chapter 2 Version Control

Chapter 3 Workflow

Chapter 4 Personalization • • • • • • • • 57

Chapter 5 Basics of Web Architecture

Chapter 6 ASP.NET, C#, and Visual Studio .NET

Chapter 7 Database Development and ADO.NET

Chapter 8 XML . . . . . • . . . . . .

Chapter 9 A Quick Overview of CMS.NET

Chapter 10 Initializing CMS.NET

Chapter 11 Getting Content into the System

Chapter 12 Cookies, Authentication, Authorization,

and Encryption . • . . • .

Chapter 13 Displaying Dynamic Content

Chapter 14 Using a Workflow to Enter Content

Chapter 15 Registered Users and Protected Content

• • 77

. . 99

. .133

. .185

. . 229

• • 267

• . 299

-345

.387

• .427

-473

v

Contents

About the Author ............................................... . xiii

Introduction ...................................................... . xv

Chapter 1 So, What Is a Content Management System Anyway? .................................................. . 1

What Is Content? .................................................... . 1 Real-World Content .................................................. . 3 What Is a Content Component? ...................................... . 5 The CMS Elements ..................................................... 6 What Is a Content Management System? .......................... .. 18 Some Common CMS Features .......................................... . 19 What Are the Benefits of a CMS? ................................ .. 24 When Do You Need a Commercial CMS? .............................. . 27 Summary .............................................................. . 28

Chapter 2 Version Control ................................ . 29

What Is Version Control? .......................................... . 29 What Is Version Tracking? ........................................ . 32 What Is Rollback? .................................................. . 33 The Roles of Version Control in a CMS .......................... .. 34 Benefits of Version Control and Tracking ....................... . 37 Summary .............................................................. . 39

Chapter 3 Workflow .......................................... .41

What Is a Workflow? ............................................... .42 Workflow Components ............................................... .43 What Is a Workflow's Role in CMS? .............................. .. 50 Building CMS Workflows ............................................ . 53 Benefits of a Workflow ............................................ . 55 Summary .............................................................. . 56

vii

Contents

Chapter 4 Personalization ................................ . 57

What Is Personalization? .......................................... . 57 Personalization Objectives ....................................... . 59

Types of Personalization .......................................... . 63

Law of Diminishing Returns ....................................... . 68

Privacy .............................................................. . 70 Role of Personalization in a CMS ................................. 71 Benefits of Personalization ...................................... . 74

Summary ............................................................... 76

Chapter 5 Basics of Web Architecture ................. 77

Basic Web Architecture ............................................ . 78

What Are Clients and Servers, Web Style? ...................... .. 82 Web Programming before • NET ...................................... . 87

Web Programming Using • NET ...................................... .. 95

Summary .............................................................. . 98

Chapter 6 ASP. NET, C#, and Visual Studio . NET ... . 99

The Simple Dynamic Content Viewer .............................. .. 99 Summary ............................................................. . 131

Chapter 7 Database Development and ADO. NET ...... . 133

Visual Studio .NET's Database Utilities ....................... . 133

What Is ADO.NET? .................................................. . 146 Examples of ADO.NET Development ................................ . 152

Summary ............................................................. . 183

Chapter 8 XML ................................................ . 185

What Is XML? ....................................................... . 185

Where Is XML Used in Web Architecture? ........................ . 188

XmlReader, XmlWri ter, and XPathNavigator ...................... . 190 XML Examples ....................................................... . 192 Summary ............................................................. . 227

viii

Contents

Chapter 9 A Quick Overview of CMS.NET .............. . 229

What Is CMS. NET? .................................................. . 230 Installing CMS. NET ................................................ . 230 A Brief Tutorial .................................................. . 247 Summary ............................................................. . 266

Chapter 10 Initializing CMS. NET ...................... . 267

To Set Up or Not to Set Up? .................................... .. 268 First, Describe the Process ..................................... . 271 Using web.config to Save the Database

Connection String ............................................. . 273 Setting Up the All-Powerful Administrator .................... . 282 Database Helper Classes and Stored Procedures ................ . 286 Finally, Wrap Up the Installation .............................. .295 Summary ............................................................. . 298

Chapter 11 Getting Content into the System ...... . 299

Breaking a Page into Frames .................................... .. 299 The XML-Driven NavBar ............................................ . 303 First CMS. NET Administration Page .............................. . 305 Content Database Table ........................................... . 306 Listing Site Content ............................................. . 307 Creating New Content ............................................. . 314 Error Handling .................................................... . 319 Updating Content .................................................. . 322 Viewing a Piece of Content ...................................... . 331 Removing Content .................................................. . 337 Submitting Content ................................................ . 340 Summary ............................................................. . 343

Chapter 12 Cookies, Authentication, Authorization, and Encryption ................................................ . 345

ASP.NET Web Application Security .............................. .. 346 CMS. NET Security Structure ...................................... . 346 Cookies and Session Objects ..................................... . 348

ix

Contents

Authentication .................................................... . 351

Authorization ...................................................... . 360

Encryption ......................................................... . 369

Restricting the CMA ............................................... . 374

NavBar Update for Handling Roles ............................... . 374

Account Maintenance .............................................. . 376

Summary ............................................................. . 386

Chapter 13 Displaying Dynamic Content ............... . 387

What Is Dynamic Content? ........................................ . 387

Three- Level Content Navigation ................................. . 388

Starting and Stopping the Web Site ............................. . 391

Navigational Database Tables .................................... . 398

User Controls ...................................................... . 401

Standard CMS. NET User Controls ................................. .402

The Default Home Page Web Form ................................. .406

The HeadlineTeaser User Control ................................ .411

The Default Content-Domain Web Form ........................... . 414

The Default Zone Web Form ....................................... .418

The Default Story Web Form ...................................... .421

Deploying Content ................................................. .424

Summary ............................................................. . 425

Chapter 14 Using a Workflow to Enter Content ..... .427

CMS. NET Content Workflow ........................................ .428

CMS.NET Roles ...................................................... . 429

Interrole Communication .......................................... .432

The Authoring Phase .............................................. .439

The Editing Phase ................................................. .447

The Approval Phase ................................................ .458

The Deployment Phase ............................................. .462

Summary ............................................................. . 471

X

Contents

Chapter 15 Registered Users and Protected Content ...................................... .473

Why Protect Content? ............................................. .474 Privacy Policy .................................................... . 474 What Are User Profiles? .......................................... .476 Methods of Gathering User Information ......................... .477

Registration Using the Slow Retrieval Method ................. .478 Logging into a Restricted Area ................................. .481 Logging Off ........................................................ . 491 Restricting Content to Registered Users ....................... .492 Summary ............................................................. . 504

xi

About the Author

Stephen Fraser is the managing principal for Fraser Training, a corporate training company focusing on .NET technologies. Stephen has over 15 years of IT experi­ence working for a number of consulting companies, ranging from the large consulting firms of EDS and Andersen Consulting (Accenture) to a number of smaller e-business companies. His IT experience covers all aspects of application and Web development and management, ranging from initial concept all the way through to deployment.

Stephen currently resides, with his beautiful wife Sarah and daughter Shaina, in beautiful Louisville, Kentucky.

xiii

Introduction

I've played with many of the commercial content management systems (CMSs) currently on the market, and many have certain qualities or features in common. There is one thing, however, that they all have in common: They are all overpriced.

Yes, they have hundreds of features. The fact is that when most Webmasters implement a CMS, they usually don't even come close to using half of the fea­tures provided by the CMS. Yes, a few Web sites are exceptions, but most don't need all the features and, unfortunately, they don't have anything available as a substitute, or so they believe.

This book will show that Web masters have an alternative because it describes the ins and outs of a CMS. It goes as far as showing you how to build one of your own-CMS.NET. But even if you never plan to write your own CMS, this book and, in particular, CMS.NET will help you understand what is happening under the covers of its more expensive siblings.

Programmers (and I am one, so I can say this) like to make the world think that what they do is very mystical. In reality, it is actually very easy, if you have enough information and the right tools at hand. This book should be enough of a head start that most good programmers could, on their own, pump out a commercial-grade CMS in less than a year. Heck, I coded CMS.NET in just over three months while writing this book.

The quick development time can be directly attributed to the power of Microsoft's .NET and Visual Studio .NET. It saved me from many of the problems that occurred when I tried to develop an equivalent CMS using other, nearly as powerful, competitive tools.

What Is This Book About?

This book is about CMSs (I'm sure you figured that out from the front cover), but more specifically, it is a detailed programmer's look at what makes up, and how to develop, a CMS using Microsoft's new ASP. NET, C#, and the .NET Framework.

Ultimately, it is a book that shows how to build a fully functional CMS at a fraction of the cost of its commercial siblings. Even if you plan to buy a much more expensive CMS, this book will explain the internal details of a CMS and should help you make the correct decision when you make your purchase.

XV

Introduction

xvi

Who Is This Book Written For?

This book is for Web developers who want to learn the internal details of a CMS or who want to create a CMS of their own. With this book, a Web developer should gain a good understanding of how to build a CMS and where to find a lot of the code (prepackaged) needed to build one.

It is for Webmasters who want a more cost -effective way to maintain their Web content. This book will show that a Webmaster may, in fact, have another choice when it comes to his CMS.

It is also for any intermediate- to advanced-level Web developers who already have a basic understanding of the Microsoft .NET Framework and want to continue to expand their knowledge. It is designed to provide a lot of helpful coding hints using C#, ASP. NET, XML, and ADO.NET, within the Visual Studio .NET environment, in the area of server-side Web development.

What Is in This Book?

The following is a chapter-by-chapter breakdown of the book's contents:

Chapter 1, "So, What Is a Content Management System Anyway?" intro­duces the basic concepts of a CMS by breaking one down and explaining its most basic elements. The chapter then continues by describing some common features and benefits of most CMSs. Finally, it wraps up with a discussion on when a commercial CMS is really merited.

Chapter 2, "Version Control," covers version control, tracking, and rollback in detail. It shows how a CMS uses versioning, why it is important, and its benefits.

Chapter 3, "Workflow," covers workflows, a very important feature found in all CMSs. It shows what a workflow is, the roles it plays, and the benefits it provides to a CMS. The chapter also discusses some things that a work­flow designer needs to examine when building the workflow.

Chapter 4, "Personalization," starts by defining personalization and walks

through its objectives. It then explores many of the different types of per­sonalization available on the market today. It covers two major issues of personalization: the law of diminishing returns and privacy. The chapter concludes with the roles and benefits that personalization provides toCMSs.

Chapter 5, "Basics ofWeb Architecture," first discusses Web architectures in general and their three layers: database, application, and presentation. Then it delves into the presentation layer in greater detail, showing how it is divided into server and client sides communicating using HTTP. The chapter then covers some of the more common client- and server-side technologies. It concludes by showing Web architectures using the .NET Framework.

Chapter 6, ·~sP.NET, C#, and Visual Studio .NET," is a little refresher on C#, ASP.NET, and Visual Studio .NET. It is designed to get everybody on a level playing field when it comes to .NET Framework development.

Chapter 7, "Database Development and ADO.NET," covers all essential aspects of database development needed to develop a CMS system.

Chapter 8, "XML," covers in great detail some of the many ways in which a developer can access XML through the .NET Framework. It covers all facets ofXML that are needed to build a CMS and, in particular, what is needed by CMS.NET.

Chapter 9, ·~Quick Overview of CMS.NET," starts with a brief description of CMS.NET and then goes into how to install it. The chapter finishes off with a brief tutorial.

Chapter 10, "Initializing CMS.NET," covers the setup subsystem of CMS.NET. It starts by showing how to navigate from page to page. Then it discusses web.config and how to programmatically update and extract information from it. The chapter also shows how CMS.NET separates application development and database development with the use of data­base helper classes.

Chapter 11, "Getting Content into the System," covers the CURVeS (creat­ing, updating, removing, viewing, and submitting) of CMS.NET's content management application. It shows how to break a Web page into frames and then revisits XML with the XML-driven NavBar (Navigation Bar). The chapter also covers error handling in some detail. It finishes by covering the Content database and its helper class.

Chapter 12, "Cookies, Authentication, Authorization, and Encryption," covers security-in particular, cookies, authentication, authorization, and encryption. It starts with a brief discussion of ASP.NET's security and then covers CMS.NET's security in more detail.

Introduction

xvii

Introduction

xviii

Chapter 13, "Displaying Dynamic Content," first covers the basics of what dynamic content is. Then it shows dynamic content in practice within CMS.NET's three-level dynamic navigation model. The chapter also covers both static and dynamic User Controls in detail.

Chapter 14, "Using a Workflow to Enter Content," covers role-based con­tent administration. It describes CMS.NET's workflow and the roles it requires. It also discusses inter-role communication and e-mail alerts.

Chapter 15, "Registered Users and Protected Content," covers registering users and restricting content. It starts by describing why you might want to restrict content and covers the privacy policy Web page. It then covers user profiles and the two most common methods of retrieving user infor­mation: the quick blitz and the slow retrieval. The chapter ends by showing how to change CMS.NET to implement registration and protected content.

Conventions

I've tried to keep the number of different styles used in this book to a minimum. You didn't buy it for pretty icons, but rather its content (I hope). Here are exam­ples of the styles used and explanations of what they mean:

• Important words and words being defined are in italic font.

• Bold font is use for things you must enter into an edit field.

• Code font is used for code, URLs, and e-mail addresses that appear in regu­lar text.

Every once in a while I will include a Note, Tip, or Warning about something:

NOTE Pay attention.

TIP Tricks that might help.

WARNING Danger ahead.

Code that is highlighted in gray can mean one of two things: it is code that you need to enter yourself, or it is code of direct interest to you. Gray background code looks like this:

public Content(string h, string s) {

headline - h; story - s;

Otherwise, code has been autogenerated by Visual Studio .NET or it is something you have entered a while ago and has no bearing on what you are coding now:

<%@ Page language="c#" Codebehind="DCViewer.aspx.cs" AutoEventWireup•"false" Inherits="Ch06Example.WebForm1" %>

<! DOCTYPE HTML PUBLIC "-I /W3C/ /DTD HTML 4.0 Transitional/ /EN" > <HTML>

Obviously, if some of the code is autogenerated and some is manually entered, you will find both styles in the code at the same time.

Introduction

xix

Introduction

XX

How to Reach the Author

I would like to hear from you. Feel free to e-mail me at srgfraser@contentmgr. com. I will respond to every e-mail that I can. Questions, comments, and suggestions are all welcome. Also, feel free to visit a copy of CMS.NET on the Internet at . www. contentmgr. com. All registered users have the capability to author content on the site if they feel so inclined. Also, the www. contentmgr. com site is where the newest release of CMS.NET can be found, along with any user /reader contributions.

Oh, by the way, thank you for buying my book.