Understanding the DotNetNuke Core Architecture- An Extension

Exclusive offer: get 50% off this eBook here
Building Websites with DotNetNuke 5

Building Websites with DotNetNuke 5 — Save 50%

Quickly build and deploy your own feature-rich website with DotNetNuke 5, VB.NET, and C#

£16.99    £8.50
by Michael Washington | April 2010 | Web Development

In this article series by Ian Lackey and Michael Washington, we will be exploring the core functionality of the DotNetNuke architecture. We will be using the Source Code version of DotNetNuke 5.2.2 that can be downloaded from the DotNetNuke CodePlex site. We will start with an overview of the architecture, touching on key concepts employed by DotNetNuke. After this, we will examine some of the major sections that make up the framework. Finally, after we learn about the objects that make up the core, we will follow a request for a page through this process to find out how each page is dynamically created.

Read Understanding the DotNetNuke Core Architecture here.

The global files

The Global.asax.vb and Globals.vb files share similar names but the parts they play in DotNetNuke are vastly different. The Global.asax.vb is used by DotNetNuke to handle application-level events raised by the ASP.NET runtime. The Globals.vb file, on the other hand, is a public module (which is the same as a static class in C#) that contains global utility functions. Before we take a look at these fi les, we first want to look at what object is being passed around in these transactions.

Global.asax.vb

Much of the logic that used to reside in the Global.asax.vb fi le has now been abstracted to the HTTP modules. We will look into the code that remains.

Application_Start

When the fi rst request is made to your application (when the fi rst user accesses the portal), a pool of HttpApplication instances are created and the Application_Start event is fi red. This will (theoretically) fire just once and on the first HttpApplication object in the pool. When there is inactivity on your portal for a certain amount of time, the application (or application pool) will be recycled. When the pool is recycled, your application will restart (and this event will fi re again) when the next request is made for your application.

As the new version of DotNetNuke uses the .NET website structure, you will find the Global.asax.vb fi le in the App_Code folder.

In the Application_Start, we are loading all of the confi gured providers to ensure they are available to the rest of the framework when needed. These are performed in the Application_Start because we want them to be called only once.

Private Sub Application_Start(ByVal Sender As Object, ByVal E As
EventArgs)
If Config.GetSetting("ServerName") = "" Then
ServerName = Server.MachineName
Else
ServerName = Config.GetSetting("ServerName")
End If
ComponentFactory.Container = New SimpleContainer()
'Install most Providers as Singleton LifeStyle
ComponentFactory.InstallComponents _
(New ProviderInstaller("data", GetType(DotNetNuke.Data.DataProvider)))
ComponentFactory.InstallComponents _
(New ProviderInstaller("caching", GeType(Services.Cache.
CachingProvider)))
ComponentFactory.InstallComponents _
(New ProviderInstaller("logging", GetType(Services.Log.EventLog.
LoggingProvider)))
ComponentFactory.InstallComponents _
(New ProviderInstaller("scheduling", GetType(Services.Scheduling.
SchedulingProvider)))
ComponentFactory.InstallComponents _
(New ProviderInstaller("searchIndex", GetType(Services.Search.
IndexingProvider)))
ComponentFactory.InstallComponents _
(New ProviderInstaller("searchDataStore", GetType(Services.Search.
SearchDataStoreProvider)))
ComponentFactory.InstallComponents_
(New ProviderInstaller("friendlyUrl", GetType(Services.Url.
FriendlyUrl.FriendlyUrlProvider)))
ComponentFactory.InstallComponents _
(New ProviderInstaller("members", GetType(DotNetNuke.Security.
Membership.MembershipProvider)))
ComponentFactory.InstallComponents _
(New ProviderInstaller("roles", GetType(DotNetNuke.Security.Roles.
RoleProvider)))
ComponentFactory.InstallComponents _
(New ProviderInstaller("profiles", GetType(DotNetNuke.Security.
Profile.ProfileProvider)))
ComponentFactory.InstallComponents _
(New ProviderInstaller("permissions", GetType(DotNetNuke.Security.
Permissions.PermissionProvider)))
ComponentFactory.InstallComponents _
(New ProviderInstaller("outputCaching", GetType(DotNetNuke.Services.
OutputCache.OutputCachingProvider)))
ComponentFactory.InstallComponents _
(New ProviderInstaller("moduleCaching", GetType(DotNetNuke.Services.
ModuleCache.ModuleCachingProvider)))
Dim provider As DotNetNuke.Security.Permissions.
PermissionProvider = _
DotNetNuke.ComponentModel.ComponentFactory.GetComponent _
(Of DotNetNuke.Security.Permissions.PermissionProvider)()
If provider Is Nothing Then
ComponentFactory.RegisterComponentInstance _
(Of DotNetNuke.Security.Permissions.PermissionProvider) _
(New DotNetNuke.Security.Permissions.PermissionProvider())
End If
'Install Navigation and Html Providers as NewInstance
Lifestyle (ie a new instance is generated each time the type is
requested, as there are often multiple instances on the page)
ComponentFactory.InstallComponents _
(New ProviderInstaller("htmlEditor", _
GetType(Modules.HTMLEditorProvider.HtmlEditorProvider), _
ComponentLifeStyleType.Transient))
ComponentFactory.InstallComponents _
(New ProviderInstaller("navigationControl", _
GetType(Modules.NavigationProvider.NavigationProvider), _
ComponentLifeStyleType.Transient))
End Sub

In previous versions of DotNetNuke, there was a great deal happening in this method. However, this code has been moved into various methods inside of the Initialize class. This was done to support the integrated pipeline mode of IIS 7.

If you would like to take a look at what is happening inside of the Initialize class, it can be found in the \Common folder of the DotNetNuke.Library project.

Examining Application_BeginRequest

The Application_BeginRequest is called for each request made to your application. In other words, this will fi re every time a page (tab), or other web request handlers such as a web service or an ashx handler, is accessed in your portal. This section is used to implement the scheduler built into DotNetNuke. Starting in version 2.0, two items, "users online" and "site log", require recurring operations. Also in this method is the call to the Initialize.Init() method that was moved out of the Appli cation_Startup method as mentioned previously.

You can fi nd out more about the scheduler by looking at the DotNetNuke Scheduler.pdf document (only if you download the documentation pack). Also note that, there is a host setting that defi nes the running mode of a scheduler, you can check for a scheduler run on every request to your portal, or run the scheduler in a timer mode.

Private Sub Global_BeginRequest(ByVal sender As Object, _
ByVal e As EventArgs) Handles Me.BeginRequest
Dim app As HttpApplication = CType(sender, HttpApplication)
Dim Request As HttpRequest = app.Request
If Request.Url.LocalPath.ToLower.EndsWith("scriptresource.axd") _
OrElse Request.Url.LocalPath.ToLower.EndsWith("webresource.axd") _
OrElse Request.Url.LocalPath.ToLower.EndsWith("gif") _
OrElse Request.Url.LocalPath.ToLower.EndsWith("jpg") _
OrElse Request.Url.LocalPath.ToLower.EndsWith("css") _
OrElse Request.Url.LocalPath.ToLower.EndsWith("js") Then
Exit Sub
End If
' all of the logic which was previously in Application_Start
' was moved to Init() in order to support IIS7 integrated pipeline
mode
' ( which no longer provides access to HTTP context within
Application_Start )
Initialize.Init(app)
'run schedule if in Request mode
Initialize.RunSchedule(Request)
End Sub

The Globals.vb file

As part of the namespace-reorganization effort associated with DotNetNuke version 3.0, general utility functions, constants, and enumerations have all been placed in a public module (as just mentioned, module here refers to VB.NET module keyword, not a DotNetNuke module) named Globals . As items in a .NET module are inherently shared, you do not need to instantiate an object in order to use the functions found here. In this module, you will find not only global constants, as shown in the following code:

Public Const glbRoleAllUsers As String = "-1"
Public Const glbRoleSuperUser As String = "-2"
Public Const glbRoleUnauthUser As String = "-3"
Public Const glbRoleNothing As String = "-4"
Public Const glbRoleAllUsersName As String = "All Users"
Public Const glbRoleSuperUserName As String = "Superuser"
Public Const glbRoleUnauthUserName As String =
"Unauthenticated Users"
Public Const glbDefaultPage As String = "Default.aspx"
Public Const glbHostSkinFolder As String = "_default"
Public Const glbDefaultControlPanel As String = "Admin/
ControlPanel/IconBar.ascx"
Public Const glbDefaultPane As String = "ContentPane"
Public Const glbImageFileTypes As String = "jpg,jpeg,jpe,gif,
bmp,png,swf"
Public Const glbConfigFolder As String = "\Config\"
Public Const glbAboutPage As String = "about.htm"
Public Const glbDotNetNukeConfig As String = "DotNetNuke.
config"
Public Const glbSuperUserAppName As Integer = -1
Public Const glbProtectedExtension As String = ".resources"
Public Const glbEmailRegEx As String = "\b[a-zA-Z0-9._%\-
+']+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,4}\b"
Public Const glbScriptFormat As String = "<script type=""text/
javascript"" src='//dgdsbygo8mp3h.cloudfront.net/sites/default/files/blank.gif' data-original=""{0}"" ></script>"

 

but a tremendous number of public functions to help you do everything, from retrieving the domain name, as shown:

Public Function GetDomainName(ByVal Request As HttpRequest, ByVal
ParsePortNumber As Boolean) As String

to setting the focus on a page:

Public Sub SetFormFocus(ByVal control As Control)

This one file contains a wealth of information for the developer. As there are more than 3070 lines in the fi le and the methods are fairly straightforward, we will not be stepping through this code.

The Globals.vb fi le can now be found in the DotNetNuke.Library project in the \Common folder.

Putting it all together

We have spent some time looking at some of the major pieces that make up the core architecture. You might be asking yourself how all this works together. In this section, we will walk you through an overview version of what happens when a user requests a page on your portal.

A shown in the preceding diagram, when a user requests any page on your portal, the HTTP Modules that have been declared in the web.config file are hooked into the pipeline. Typically, these modules use the Init method to attach event handlers to application events.

The request then goes through the Global.asax page. As just mentioned, some of the events fi red here will be intercepted and processed by the HTTP modules, but the call to run the scheduler will happen in this fi le.

Next, the page that was requested, Default.aspx, will be processed. As we stated at the beginning of this article, all requests are sent to the Default.aspx page and all the controls and skins needed for the page are created dynamically by reading the tabID from the requested URL. So let's begin by looking at the HTML for this page.

Building Websites with DotNetNuke 5 Quickly build and deploy your own feature-rich website with DotNetNuke 5, VB.NET, and C#
Published: April 2010
eBook Price: £16.99
Book Price: £27.99
See more
Select your format and quantity:

The HTML of the page is pretty simple and straightforward. The attributes at the top of the page tell us that the HTML page inherits from the DotNetNuke.Framework. CDefault class, which is found in the Default.aspx.vb code-behind page. We will be examining this class soon.

<%@ Page Language="vb" AutoEventWireup="false" Explicit="True"
Inherits="DotNetNuke.Framework.DefaultPage" CodeFile="Default.
aspx.vb" %>

The title and meta tags are populated dynamically from variables in the PortalSettings class via a method in the code-behind fi le:

<head id="Head" runat="server">
<meta content="text/html; charset=UTF-8" http-equiv="Content-
Type"/>
<meta content="text/javascript" http-equiv="Content-Script-Type"/>
<meta content="text/css" http-equiv="Content-Style-Type"/>
<meta id="MetaRefresh" runat="Server" http-equiv="Refresh"
name="Refresh" />
<meta id="MetaDescription" runat="Server" name="DESCRIPTION" />
<meta id="MetaKeywords" runat="Server" name="KEYWORDS" />
<meta id="MetaCopyright" runat="Server" name="COPYRIGHT" />
<meta id="MetaGenerator" runat="Server" name="GENERATOR" />
<meta id="MetaAuthor" runat="Server" name="AUTHOR" />
<meta name="RESOURCE-TYPE" content="DOCUMENT" />
<meta name="DISTRIBUTION" content="GLOBAL" />
<meta id="MetaRobots" runat="server" name="ROBOTS" />
<meta name="REVISIT-AFTER" content="1 DAYS" />
<meta name="RATING" content="GENERAL" />
<meta http-equiv="PAGE-ENTER" content="RevealTrans(Duration=0,Tra
nsition=1)" />

After the meta tags, placeholders are set to hold CSS and favicons. These are declared in this manner so that the actual fi les can be determined by the skin being used on the site. This is followed by a script declaration for the fi le; this declaration is responsible for the module drag-and-drop capability of DotNetNuke 3.0 and later.

<style type="text/css" id="StylePlaceholder" runat="server"></style>
<asp:placeholder id="CSS" runat="server" />
</head>

The body of the HTML is relatively bare. The important code in this section is the SkinPlaceholder, used to inject the selected skin into the body of the page.

<body id="Body" runat="server" >
<dnn:Form id="Form" runat="server" ENCTYPE="multipart/form-data" >
<asp:Label ID="SkinError" runat="server" CssClass="NormalRed"
Visible="False"></asp:Label>
<asp:PlaceHolder ID="SkinPlaceHolder" runat="server" />
<input id="ScrollTop" runat="server" name="ScrollTop"
type="hidden" />
<input id="__dnnVariable" runat="server" name="__dnnVariable"
type="hidden" />
</dnn:Form>
</body>
</html>

Now we will venture into the code-behind class for this fi le. If you look past the Imports statements, you will see that this class inherits from the DotNeNuke. Framework.PageBase base class.

Partial Class DefaultPage
Inherits DotNetNuke.Framework.CDefault

Its base class handles the localization for the page and of course, as this is a web page, inherits from System.Web.UI.Page.

The first procedure that is run in the page is the Page_Init method. Most of the action required to generate the response to our request resides in this section. As shown in the next diagram, the first action the Page_init method takes is to call the InitializePage, which generates the information to fill the meta tags. After initializing the page, the Page_Init method begins configuring the skin by setting the DOCTYPE for the page and verifies that the requested page is enabled.

If you look at a couple of pieces of code, we can see some of the fi les we looked at earlier in use. In the InitializePage method, we make use of both the PortalSettings class and the Current property of the HttpContext object to retrieve the TabName:

objTab = objTabs.GetTabByName(Request.QueryString("TabName"),
CType(HttpContext.Current.Items("PortalSettings"), PortalSettings).
PortalId)

Once the properties of the page are retrieved, the process of loading the skin begins. The process starts by retrieving a skin control from the GetSkin method of the Skin object that will do the work of loading the skin.

' load skin control
Dim ctlSkin As DotNetNuke.UI.Skins.Skin = _
DotNetNuke.UI.Skins.Skin.GetSkin(Me)

After determining whether the request is a skin preview, the code moves on to load the skin. There are three possible outcomes when loading the skin: it is for an admin page, it is for a regular page, or there was an error and it loads the default skin. Regardless of which section is invoked, the skin is loaded using the LoadSkin method.

ctlSkin = LoadSkin(Page, skinSource)

This method reads the physical path of the skin control and loads it into our ctlSkin variable. And fi nally, there are calls to ManageStyleSheets and ManageFavicon, and the control is added to the page by using the SkinPlaceholder that we looked at earlier in the HTML page:

' add CSS links
ManageStyleSheets(False, ctlSkin)
' add skin to page
SkinPlaceHolder.Controls.Add(ctlSkin)
' add CSS links
ManageStyleSheets(True, ctlSkin)
' add Favicon
ManageFavicon()
' ClientCallback Logic
DotNetNuke.UI.Utilities.ClientAPI _
.HandleClientAPICallbackEvent(Me)

At this point, you may be thinking to yourself, "I understand how the skin is dynamically added to the page for a user's request, but how are the modules dynamically added?" Well, to get the answer to that question, we will need to look at the skin control itself. You can fi nd the skin control (skin.vb) in the UI\Skins folder of the DotNetNuke.Library project. We will not look at this entire class, but if you look closely at the OnInit method, which is called when the control is instantiated, you will see how the modules are created. First, all of the panes for the skin are loaded into the Skin object's Panes property. Then a check is made to determine if the requested page is an admin/edit view. Based on this information, one of two methods are called to load the modules for the request.

'Load the Module Control(s)
If Not IsAdminControl() Then
' master module
bSuccess = ProcessMasterModules()
Else
' slave module
bSuccess = ProcessSlaveModule()
End If

These methods determine which modules should be loaded and verify that the requesting user has access to the module(s), determines which pane to place the module, and fi nally inject the module into the skin.

'try to inject the module into the pane
bSuccess = InjectModule(pane, objModule)

This procedure will be repeated for all of the modules associated with that page, and the request is fi nally completed and presented to the user. Of course, we did not cover every piece of code that is called in the process, but hopefully have given you a path to follow to continue researching the core architecture on your own.

Summary

In this article, we have taken a look at how the core of DotNetNuke works. We looked at a general overview, examined important pieces of the framework, and finally followed a request through its paces.

If you have read this article you may be interested to view :

Building Websites with DotNetNuke 5 Quickly build and deploy your own feature-rich website with DotNetNuke 5, VB.NET, and C#
Published: April 2010
eBook Price: £16.99
Book Price: £27.99
See more
Select your format and quantity:

About the Author :


Michael Washington

Michael Washington is a Website developer and an ASP.NET, C#, and Visual Basic programmer. He is a DotNetNuke Core member and has been involved with DotNetNuke for over 3 years. He is the author of numerous DotNetNuke modules and tutorials. He is one of the founding members of the Southern California DotNetNuke Users group. He has a son, Zachary and resides in Los Angeles with his wife Valerie.

Books From Packt

jQuery 1.4 Reference Guide
jQuery 1.4 Reference Guide

jQuery UI 1.7: The User Interface Library for jQuery
jQuery UI 1.7: The User Interface Library for jQuery

Drupal 6 Attachment Views
Drupal 6 Attachment Views

Joomla! 1.5: Beginner's Guide
Joomla! 1.5: Beginner's Guide

Grok 1.0 Web Development
Grok 1.0 Web Development

Apache MyFaces 1.2 Web Application Development
Apache MyFaces 1.2 Web Application Development

Magento 1.3: PHP Developer's Guide
Magento 1.3: PHP Developer's Guide

Drupal 7 First look
Drupal 7 First look

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software