Understanding the DotNetNuke Core Architecture- An Extension

0
123
7 min read

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=""{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.


Subscribe to the weekly Packt Hub newsletter

* indicates required

LEAVE A REPLY

Please enter your comment!
Please enter your name here