[OK]を私は少しこの1つで眠っていたが、私はきれいな解決策を考え出した。マスターページの基本クラスの代わりに、ページの基本クラスを使用することになりました。ベースページは、ベースマスターページで設定する予定のメタを設定します。
Public Class PageBase
Inherits Page
Private _DocDetails As FolderDocument
Public Overridable ReadOnly Property DocDetails() As FolderDocument
Get
Return _DocDetails
End Get
End Property
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack() Then
SetMeta()
End If
End Sub
Protected Sub SetMeta()
If DocDetails IsNot Nothing Then
Page.Title = DocDetails.MetaTitle
If DocDetails.MetaKeywords <> String.Empty Then
Dim metaKeywords As New HtmlMeta()
metaKeywords.Name = "Keywords"
metaKeywords.Content = DocDetails.MetaKeywords
Page.Header.Controls.Add(metaKeywords)
End If
If DocDetails.MetaDescription <> String.Empty Then
Dim metaDescription As New HtmlMeta()
metaDescription.Name = "Description"
metaDescription.Content = DocDetails.MetaDescription
Page.Header.Controls.Add(metaDescription)
End If
End If
End Sub
End Class
..そして、aspxページはこのベースページを継承し、マスターページを動的に設定します。
<%@ Page Language="VB" Inherits="PageBase" %>
<script runat="server">
Private _DocDetails As FolderDocument
Public Overrides ReadOnly Property DocDetails() As FolderDocument
Get
Return _DocDetails
End Get
End Property
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs)
_DocDetails = FolderDocuments.GetFolderDocument()
If _DocDetails IsNot Nothing Then
If _DocDetails.MasterPage <> "" Then
Me.MasterPageFile = String.Format("~/templates/{0}.master", _DocDetails.MasterPage)
End If
End If
End Sub
</script>
...と動的と呼ばれるマスターページに私が鋳造することで、ページの基本クラスを参照することができます。
Dim parentPage As PageBase = DirectCast(Page, PageBase)
Response.write(parentPage.DocDetails.Title)
をはい、これは動作しますが、私の知る限りでは、あなたが(強い型付けを失います特別な作業をせずに)。 – ScottE
私は一般的に、静的プロパティクラスまたはインスタンスクラスのいずれかを使用してHttpContext.Itemsコレクションを渡す必要がある状況を包み込みました。意味私はアイテムに入れたデータのプロパティを持つContextItemsクラスのようなものを持っています。私はそこに入力して、Itemsコレクションのデータを型付きクラスとして返すようにします。 –