Tải bản đầy đủ (.pdf) (336 trang)

Building websites with dotnetnuke 5

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (6.69 MB, 336 trang )

Building Websites with
DotNetNuke 5
Quickly build and deploy your own feature-rich website
with DotNetNuke 5, VB.NET, C#, and Silverlight
Michael Washington
Ian Lackey

BIRMINGHAM - MUMBAI
Building Websites with DotNetNuke 5
Copyright © 2010 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the authors, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
First published: April 2010
Production Reference: 1310310
Published by Packt Publishing Ltd.
32 Lincoln Road
Olton
Birmingham, B27 6PA, UK.
ISBN 978-1-847199-92-8
www.packtpub.com


Cover Image by John M. Quick ()
Credits
Authors
Michael Washington
Ian Lackey
Reviewers
Rahul Singla
Andrew The
Acquisition Editor
Dilip Venkatesh
Development Editor
Mayuri Kokate
Technical Editor
Smita Solanki
Indexer
Monica Ajmera Mehta
Editorial Team Leader
Aanchal Kumar
Project Team Leader
Lata Basantani
Project Coordinator
Joel Goveya
Proofreader
Lynda Sliwoski
Graphics
Geetanjali Sawant
Production Coordinator
Shantanu Zagade
Cover Work
Shantanu Zagade

About the Authors
Michael Washington is a website developer and an ASP.NET, C#, and Visual
Basic programmer. He is a Microsoft MVP in Silverlight. He has served as a
DotNetNuke Core member for many years. He is the author of the Custom Module
Development chapter in Building Websites with VB.NET and DotNetNuke 4
(Packt Publishing).
He has authored over 100 pages of tutorials on his sites at
http://ADefWebserver.
com
and , covering DotNetNuke and Silverlight.
He is one of the founding members of the Southern California DotNetNuke Users
group (
www.socaldug.org). He is also the author of The DotNetNuke 4 Module
Development Guide, as well as numerous popular DotNetNuke modules such as
.
He has a son, Zachary, and resides in Los Angeles with his wife, Valerie.
I would like to dedicate this book to my Valerie and my son Zachary.
I do it all for you!
Ian Lackey worked as a systems engineer for a St. Louis-based ISP from
1999 to 2002. At that time, he began developing web applications using ASP
and migrated to ASP.NET shortly before the 2.0 release. Ian now works as a
full-time programmer analyst II for Washington University in St. Louis Medical
School - Department of Pediatrics. He also runs a small business, DigitalSnap Inc.
() that provides complete DotNetNuke solutions as
well as individual modules ().
Currently Ian is involved in community-driven areas such as the OpenLight Group
(
), which manages open source projects including
several DotNetNuke modules and many Silverlight-based applications. He will also
be speaking at the St. Louis .NET user group () meetings

this year.
Ian currently lives in a small town in Illinois, just East of St. Louis, with his wife Julie
(
o) and two daughters, Britney and Brooklynn.
To everyone in my family, especially Loven and my little B's, thank
you so much for your love and support through many long nights
behind a laptop. You all are my greatest blessing. Love you forever
and always.
About the Reviewers
Rahul Singla is a software professional (often lling the additional roles of
Business Analyst and Project Manager) based in Karnal (India).
A university topper in his college during graduation and post graduation, he
currently operates a software rm, called Imbibe Inc., and a technical training
institute, Imbibe Knowledge Enterprise. His work has ranged from developing
proof-of-concept JME applications to end-to-end solutions for organizations. He
often freelances on medium to large scale projects, has had some popular articles
on CodeProject published, and also maintains a CVS account at
drupal.org.
Particularly fond of sharing his development experiences with his students, he likes
to indulge in micro-ying, travelling, and just lying around in his vacant time. Pretty
wary of his schedule, and his inability to spend time with his family, his newborn
nephew is his new attraction.
You can nd more about Rahul at his portal
. You
might also want to check out his technical blog at />blog
, where you can nd free DotNetNuke 4.x/5.x modules. You can contact him at

As always, I will dedicate my work rst to the Almighty, who gave
me the strength, perseverance, and opportunity to reach here, and
then to the three most important people in my life, my father, my

mother, and Rmi (my brother).
Andrew The ("The" is his last name, pronounced Tay) currently works as a
developer and system engineer for the Los Angeles County of Education in Los
Angeles, CA. Andrew started programming in Oracle's PL/SQL on Sun Solaris.
Since then, he has worked with various platforms, databases, and languages (AIX,
Perl, Korn Shell, DB2, HTML, SQL Server, and C#). He now primarily works with
the Microsoft stack (Windows, .NET, and SQL Server).

Table of Contents
Preface 1
Chapter 1: What is DotNetNuke? 7
Open source web portals 7
What is a web portal? 8
Common portal features 8
Why DotNetNuke? 10
PHP-Nuke 11
Joomla! 11
DotNetNuke 11
Benefits of using an established program 14
The DotNetNuke community 14
Core team 14
The DotNetNuke discussion forum 15
The bug tracker 15
The DotNetNuke project Roadmap team 16
The license agreement 16
Coffee Connections 16
Determining client needs 17
What is a user story? 17
Advantages of using user stories 18
Coffee Connections user stories 19

Summary 19
Chapter 2: Installing DotNetNuke 21
Installing DotNetNuke (local version) 22
Clean installation 22
Downloading the code 22
Setting up an application 23
Verifying default documents 26
Setting security permissions 28
Table of Contents
[ ii ]
Setting up the database 31
Running the install wizard 34
Upgrading 42
Upgrading the checklist 42
Backing up your database 44
Backing up your DotNetNuke files 46
Performing the upgrade 46
Summary 50
Chapter 3: Users, Roles, and Pages 51
User accounts 52
Who is a user? 52
Creating user accounts 52
Setting required registration fields 55
Managing your own profile 59
Registering a user manually 60
Understanding DotNetNuke roles and role groups 62
Assigning security roles to users 68
Role advanced settings 70
Understanding DotNetNuke pages and tabIDs 72
Administering pages 81

Summary 82
Chapter 4: Standard DotNetNuke Modules 83
DotNetNuke modules 84
Adding a module 84
Module Settings 85
Editing a module 85
Importing and exporting
content 86
Syndicate information 86
Help and Online Help documentation 86
Editing module functionality 86
Changes to the organization of modules 90
Standard modules 91
Account Login module 91
Practical purposes 91
Administration and modification 91
Special features 92
Banner module 93
Console module 93
Administration and modification 93
Feed Explorer module 94
Administration and modification 94
HTML module 95
Practical purposes 95
Table of Contents
[ iii ]
Administration and modification 95
Special features and additional
information 95
Search Input and Search Results module 96

Practical purposes 96
Administration and modification 96
Additional Modules 97
Announcements module 97
Practical purposes 97
Administration and modification 98
Special features and additional information 99
Blog module 99
Administration and modification 99
Special features 101
Chat module 101
Administration and modification 101
Special features 101
Contacts module 101
Practical purposes 101
Administration and modification 102
Special features 102
Documents module 102
Practical purposes 102
Administration and modification 102
Special features and additional
information 103
Events module 103
Practical purposes 104
Administration and modification 104
Special features and additional information 105
FAQs module 105
Practical purposes 105
Administration and modification 105
Special features and additional

information 106
Feedback module 106
Practical purposes 106
Administration and modification 106
Special features and additional information 107
Form and List module 107
Practical purposes 107
Administration and modification 107
Special features and additional information 108
Forums module 108
Practical purposes 108
Administration and modification 109
Gallery module 109
Practical purposes 110
Administration and modification 110
Help module 111
Table of Contents
[ iv ]
Practical purposes 111
Administration and modification 111
IFrame module 112
Practical purposes 112
Administration and modification 112
Special features and additional information 113
Links module 113
Practical purposes 113
Administration and
modification 114
Special features and additional information 115
Map module 115

Practical purposes 115
Administration and modification 115
Special features and additional information 116
Media module 116
Practical purposes 116
Administration and modification 117
News Feed (RSS) module 117
Practical purposes 117
Administration and modification 117
Special features 118
Reports module 118
Administration and modification 118
Special features and additional information 119
Repository module 119
Practical purposes 120
Administration and modification 120
Store module 121
Practical purposes 121
Administration and modification 121
Special features and additional information 122
Survey module 122
Administration and modification 122
Users Online module 123
Administration and modification 123
Wiki module 124
Practical purposes 124
Administration and modification 124
Special features and additional information 125
XML/XSL module 125
Practical purposes 125

Administration and modification 126
Special features and additional information 126
Third-party modules 126
Commercial modules 126
Developers and vendors 127
Table of Contents
[ v ]
Open source modules 128
Developers and vendors 129
Summary 130
Chapter 5: Host and Admin Tools 131
The difference between host and admin 131
Admin tools 132
Site Settings 133
Basic Settings 133
Advanced Settings 136
Stylesheet Editor 138
Pages 139
Extensions 139
Languages 140
Skins 140
Security Roles 140
User Accounts 140
Vendors 141
Site Log 141
Newsletters 142
File Manager 145
Recycle Bin 148
Event Viewer 148
Site Wizard 150

Google Analytics 150
Host tools 150
Host Settings 150
Basic Settings 150
Advanced Settings 153
Portals 160
Module definitions 160
File Manager 161
Vendors 161
SQL 164
Schedule 165
Languages 165
Search Admin 165
Lists 166
Superuser Accounts 166
Extensions 167
Dashboard 167
What's New 168
Marketplace 169
Table of Contents
[ vi ]
Extra options on the ADMIN menu 169
Common Tasks 170
Summary 170
Chapter 6: Understanding the DotNetNuke Core Architecture 171
Architecture overview 171
Diving into the core 174
Using the Context object in your application 174
The PortalSettings class 176
Working with the configuration files 181

The web.config file 182
Configuring the providers used in DotNetNuke 182
Handling the providers 185
HTTP modules 190
Application settings 195
The global files 196
Global.asax.vb 196
Application_Start 196
Examining Application_BeginRequest 199
The Globals.vb file 200
Putting it all together 201
Summary 206
Chapter 7: Custom Module Development 207
The Coffee Shop Listing module 207
The development environment 209
Creating the view control 210
Displaying the module 214
View control summary 217
The module folder structure 217
Inheriting from PortalModuleBase 218
Module configuration 219
Diagnosing errors using the Log Viewer 219
Navigation 220
NavigateURL 220
IActionable 222
Updating the configuration 224
Navigating from ShopList to EditShopList 224
Navigation summary 225
NavigateURL 225
IActionable 226

Localization 227
Localizing static content 228
Localizing dynamic content 229
Table of Contents
[ vii ]
Localizing the content 230
Summary 231
Chapter 8: Connecting to the Database 233
The DAL, DAL+, and LINQ to SQL 233
The DAL 233
The DAL+ 234
LINQ to SQL 234
Summary of the data connection methods 235
The database scripts 235
Executing the install script 237
Creating the LINQ to SQL DataContext class 238
The Settings page 240
Creating the Settings page 240
The Settings page 244
Inheriting from ModuleSettingsBase 244
Overriding LoadSettings and UpdateSettings 244
Storing values in ModuleSettings 244
Updating the configuration 245
The EditShopList page 245
The EditShopList.ascx file 246
The EditShopList code behind file 249
The remaining methods for EditShopList 253
The ShopList page 253
The ShopList.ascx file 254
The ShopList code behind file 257

SetProfile/GetProfile 261
GetModuleSettings 263
The remaining methods for ShopList 264
Summary 264
Chapter 9: Silverlight Coffee Shop Viewer 265
Silverlight and DotNetNuke 265
Creating the web service 266
Getting coffee shops 267
Getting last used zip code 270
Creating the WebService.asmx entry point 271
The Silverlight application 273
Adding reference to System.Windows.Controls.Data 275
The web service proxy 276
The Application_Startup page 278
The Silverlight Coffee Shop Viewer UI 279
The Silverlight Coffee Shop Viewer code 282
Building the Silverlight project and moving the .XAP 286
Table of Contents
[ viii ]
Altering Coffee Shop Viewer to launch the Silverlight application 287
The ShopList UI 288
The ShopList code 289
Packaging the module 291
Deploying the module 292
Summary 292
Chapter 10: Creating Multiple Portals 293
Multiple portals 294
Parent portals versus child portals 296
Setting up a parent portal 296
Registering your domain and setting the DNS 296

Creating a parent portal 297
Setting up a child portal 298
Creating portal templates 300
Using the Site Wizard 301
Managing multiple portals 305
Summary 306
Index 307
Preface
The book starts off by giving you a deep understanding of working with basic
DotNetNuke sites, guiding you through the features and giving you the condence
to create and manage your site.
After that, you will journey to the heart of DotNetNuke and learn about its core
architecture. Always concise, relevant, and practical, you will nd out what makes
DotNetNuke tick, and from there, you will be ready to customize DotNetNuke.
Developers will enjoy the detailed walkthrough of creating new custom modules.
Special emphasis is given to using Linq to SQL and Silverlight to invigorate your
module development.
You will master all of this as you leap into the development of a DotNetNuke 5 site.
What this book covers
Chapter 1, What is DotNetNuke? explains the meaning and purpose of web portals,
what successful web portals have in common, the different types of open source
web portals, and also discusses why we selected DotNetNuke. In this chapter, we
introduce our ctional client Coffee Connections, and using user stories, gather the
requirements to build a site for it.
Chapter 2, Installing DotNetNuke explains how easy it is to set up a DotNetNuke site
on your local workstation. This process has become much easier with each release of
DNN, and we expect to continue to see improvements in this area as new versions
are released. Some of the new features included in the installation wizard allow you
to get your site up and running without needing to modify additional settings once
the portal is installed.

Chapter 3, Users, Roles, and Pages covers the concepts of users, roles, and pages. This
should lay a foundation for the rest of the information we cover in this book. Most of
the concepts we will cover will deal with one or all of these items.
Preface
[ 2 ]
Chapter 4, Standard DotNetNuke Modules discusses the administration, common
features, and settings of modules in a DotNetNuke portal. This includes how to add
modules to a page, how to adjust layout options, and permission modules. It also
covers the standard modules that come prepackaged with DotNetNuke, their basic
uses as well as situations they may be used in. It gives a brief overview of all of the
modules developed by the DotNetNuke team of developers. These modules range
from simple content display to fully interactive forums and e-commerce solutions.
After discussing the modules available from the DotNetNuke team, this chapter
discusses third-party commercial and open source modules. After covering the pros
and cons of using commercial and open source modules, it reviews a brief list of
vendors from both of these groups.
Chapter 5, Host and Admin Tools covers a variety of information. It gives you, as the
administrator of a DotNetNuke portal, the skills needed to maintain your website.
Chapter 6, Understanding the DotNetNuke Core Architecture explains how the core of
DotNetNuke works. It gives a general overview, examining important pieces of the
framework, and nally follows a request through its paces.
Chapter 7, Custom Module Development covers many important concepts that you
will most likely use in every module you create. In addition to navigation and
localization, it also covers exception handling that will aid you in your module
development.
Chapter 8, Connecting to the Database explains how to set up our development
environment, create controls, and the data access layer.
Chapter 9, Silverlight Coffee Shop Viewer explains the UI and the Silverlight application.
It also shows how to package the module so that it can be distributed to another
DotNetNuke website.

Chapter 10, Creating Multiple Portals explains how to create multiple portals that can
all be hosted from one account. It shows how to create and use templates, how to
use the Site Wizard to upgrade your site, and how to manage these portals once
they have been set up. Not only will this functionality allow you to create multiple
portals, but as all of the information is stored in one database, backing up them
is simple.
Preface
[ 3 ]
What you need for this book
Windows Vista (or higher)
SQL Server 2005 (or higher)
Visual Studio 2008 (or higher)
Expression Blend 3 (or higher)
DotNetNuke 5.2 (or higher)
Who this book is for
This book has been written for both the beginner wanting to set up a website and
also ASP.NET developers with a grasp of VB.NET and C# who want a deeper
understanding of how to work with DotNetNuke. To work with the DotNetNuke
code, you will need access to Visual Web Developer Express or Visual Studio .NET
2010. No prior knowledge of DotNetNuke is assumed.
Conventions
In this book, you will nd a number of styles of text that distinguish between
different kinds of information. Here are some examples of these styles, and an
explanation of their meaning.
Code words in text are shown as follows: "We will place them in the Coffee Shop
Listing folder that is under the
DesktopModules folder."
A block of code is set as follows:
<%@ Control Language="VB"
AutoEventWireup="true"

CodeFile="Settings.ascx.vb"
Inherits="CoffeeShopVB.Settings" %>





Preface
[ 4 ]
New terms and important words are shown in bold. Words that you see on the
screen, in menus or dialog boxes for example, appear in the text like this: "If this
option is selected, an additional option Add to new pages only is displayed is
also shown".
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or may have disliked. Reader feedback is important for
us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to
,
and mention the book title via the subject of your message.
If there is a book that you need and would like to see us publish, please
send us a note in the SUGGEST A TITLE form on
www.packtpub.com or
e-mail
If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book on, see our author guide on
www.packtpub.com/authors.
Customer support

Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.
Downloading the example code for the book
Visit to
directly download the example code.
The downloadable les contain instructions on how to use them.
Preface
[ 5 ]
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you nd a mistake in one of our books—maybe a mistake in the text
or the code—we would be grateful if you would report this to us. By doing so, you
can save other readers from frustration and help us improve subsequent versions
of this book. If you nd any errata, please report them by visiting
http://www.
packtpub.com/support
, selecting your book, clicking on the let us know link, and
entering the details of your errata. Once your errata are veried, your submission
will be accepted and the errata will be uploaded on our website, or added to any list
of existing errata, under the Errata section of that title. Any existing errata can be
viewed by selecting your title from
/>Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media.
At Packt, we take the protection of our copyright and licenses very seriously. If you
come across any illegal copies of our works, in any form, on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.
Please contact us at
with a link to the suspected
pirated material.

We appreciate your help in protecting our authors, and our ability to bring you
valuable content.
Questions
You can contact us at if you are having a problem with
any aspect of the book, and we will do our best to address it.

What is DotNetNuke?
From company intranets to mom and pop shops, to local chapters of the 4-H club,
most organizations are looking to have a presence on the World Wide Web. Open
source web portals answer this demand by providing easy to install and use website
frameworks that are not only extremely functional but are also freely available.
Whether it is to sell services or to have a place to meet, web portals play an
important role in communication on the Web.
In this chapter, we will discuss the following topics:
What web portals are and what the successful web portals have in common
Different types of open source web portals and why we selected DotNetNuke
for our project over other available web portals
The benets gained by using an established framework and the benets of
using DotNetNuke specically
An introduction to Coffee Connections, our ctional client
A brief overview of Coffee Connections, determining the specic
requirements for its website and gathering the requirements using
user stories
This will give you a general overview of what to expect from this book and how to
make the most of it depending on your role and experience with web portals and
.NET development.
Open source web portals
So what does it actually mean to have a web portal? We begin this chapter with an
explanation of what a web portal is and then go on to the features of a web portal
and the reasons for selecting open source web portals.






What is DotNetNuke?
[ 8 ]
What is a web portal?
You have decided to start a web portal and rst need to nd out what makes a web
portal. Does creating a few web pages with links to different topics make it a web
portal? A web portal, in its most basic sense, aims to be an entry point to the World
Wide Web. Portals will typically offer services, such as search engines, links to useful
pages, news, forums, e-mails, and so on, depending on their targeted audience, all
in an effort to draw users to their site. In most cases, portals provide these services
for free, in hope that users will make the site their home page or at least come back
often. A couple of successful examples include Yahoo! and MSN. These sites are
horizontal portals because they typically attract a wide audience and primarily
exist to produce advertising income for their owners. Other web portals may focus
on a specic group of users or be part of a corporate intranet. Most often, they will
concentrate on one particular subject like gardening or sports. These types of portals
are vertical portals as they focus inward and cater to a selected group of people.
The type of portal you create depends on the target audience you are trying to
attract. You may discover that the portal you create is a combination of both
horizontal and vertical portals so as to address specic needs, while simultaneously
giving a broader range of services to your visitors. Regardless of the type of portal
you decide on, horizontal or vertical, they both share certain key characteristics and
functionalities that will increase the probability of users returning to your site.
Common portal features
Let us rst briey discuss the difference between a portal and a standard or
content-based website. The majority of the sites that you use on a daily basis are

designed to provide information on a particular topic or similar topics. The standard
sites usually do not provide a great deal of interactivity and have a limited number
of services. For example, many sites contain a blog, but not a forum. Generally, a
portal not only contains content, but also several interactive services or areas of
the site.
Please keep in mind that these are generalizations and are not always clearly
dened, and the differences cannot be easily identied. In fact, the difference
between a portal and a standard site is pretty much a philosophical discussion,
which can be debated from multiple positions. To get the most out of this book,
it is important for us to know the concepts outlined in the previous paragraph. It
is also important to know that the DotNetNuke framework is more than capable
of supporting a portal-oriented or a more standard website. With that said, our
example for this book is going to focus more on a portal.

×