Portal Starter 源碼深入剖析(一)

來源:互聯網
上載者:User
Portal Starter 源碼深入剖析(一)
學ASP.net光看書看來是不行的,找一些經典的原始碼來讀讀,對提升認識是很有協助的。
在Microsoft的網站上找到幾個範例,選擇Portal是因為這個範例最大,可作為一個簡單的門戶站。
Portal的工作流程:
1、讀取網站設定檔案PortalCfg.xml至context中緩衝起來,這個過程由Global.asax中的Application_BeginRequest()事件來完成的。
2、客戶訪問Portal站,執行Default.aspx,Default.aspx判斷用戶端是Mobile還是瀏覽器,如果是後者,引導客戶至DesktopDefault.aspx
3、DesktopDefault.aspx完成網站各個欄目的展示以及各個欄目中相應模組的載入。
分析Global.asax中的Application_BeginRequest()事件:

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
'預設訪問首頁
Dim tabIndex As Integer = 0
Dim tabId As Integer = 1

' Get TabIndex from querystring
If Not (Request.Params("tabindex") Is Nothing) Then
tabIndex = CInt(Request.Params("tabindex"))
End If

' Get TabID from querystring
If Not (Request.Params("tabid") Is Nothing) Then
tabId = CInt(Request.Params("tabid"))
End If

' Add the PortalSettings object to the context
' PortalSetting在Components\Configuration.vb中定義,其作用是根據傳入的tabIndex,tabId載入相應欄目的元素。
' Context用來緩衝相應欄目的設定。
Context.Items.Add("PortalSettings", New PortalSettings(tabIndex, tabId))

' Read the configuration info from the XML file or retrieve from Cache
' and add to the context
' Configuration類在Components\Configuration中定義,其作用是操作Portal網站的設定檔案PortalCfg.xml檔案。
' 同樣是將設定檔案快取到Context中,這樣網站的任何部分都可以訪問到這些設定。
Dim config As Configuration = New Configuration()
Context.Items.Add("SiteSettings", config.GetSiteSettings())

Try
If Not (Request.UserLanguages Is Nothing) Then
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages(0))
' Default to English if there are no user languages
Else
Thread.CurrentThread.CurrentCulture = New CultureInfo("en-us")
End If
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture
Catch ex As Exception
Thread.CurrentThread.CurrentCulture = New CultureInfo("en-us")
End Try
End Sub
分析New PortalSettings(tabIndex, tabId),請看下面PortalSettings的建構函式:
Public Class PortalSettings
Public PortalId As Integer
Public PortalName As String
Public AlwaysShowEditButton As Boolean
Public DesktopTabs As New ArrayList()
Public MobileTabs As New ArrayList()
Public ActiveTab As New TabSettings()
......

Public Sub New(ByVal tabIndex As Integer, ByVal tabId As Integer)

' Get the configuration data
Dim config As Configuration = New Configuration()
' 通過Configuration類中的GetSiteSettings()將PortalCfg.xml檔案匯入到Context中,
' 隨後通過傳回值賦值給siteSettings,siteSettings被定義為一個增強型的Dataset類。
Dim siteSettings As SiteConfiguration = config.GetSiteSettings()


' Read the Desktop Tab Information, and sort by Tab Order
' 讀取Tab資訊,也就是Portal網站的欄目資訊,放到DesktopTabs中。
Dim tRow As SiteConfiguration.TabRow
For Each tRow In siteSettings.Tab.Select("", "TabOrder")
Dim tabDetails As New TabStripDetails()

With tabDetails
.TabId = tRow.TabId
.TabName = tRow.TabName
.TabOrder = tRow.TabOrder
.AuthorizedRoles = tRow.AccessRoles
End With

Me.DesktopTabs.Add(tabDetails)
Next

' If the PortalSettings.ActiveTab property is set to 0, change it to
' the TabID of the first tab in the DesktopTabs collection
If Me.ActiveTab.TabId = 0 Then
Me.ActiveTab.TabId = CType(Me.DesktopTabs(0), TabStripDetails).TabId
End If


' Read the Mobile Tab Information, and sort by Tab Order
Dim mRow As SiteConfiguration.TabRow
For Each mRow In siteSettings.Tab.Select("ShowMobile='true'", "TabOrder")
Dim tabDetails As New TabStripDetails()

With tabdetails



相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。