My code check each webpart in DeclarativeCatalogPart and assign the role for them. But it doesn't run the after the DeclarativeCatalogPart1_Init life cycle. Do know how to solve it? I want all webpart "Refresh" after assigned role. Appreciate if provide any solution. Thank you.
-----------------------------------------------------------------------------------------------------
Default.aspx.vb
Protected Sub DeclarativeCatalogPart1_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles DeclarativeCatalogPart1.Init
Dim WebPartManager1 As WebPartManager = Master.FindControl("WebPartManager1")
For Each c As WebPartDescription In Me.DeclarativeCatalogPart1.GetAvailableWebPartDescriptions
Dim namingContainerID As String = "gwp"
If c.ID = namingContainerID + "Announcement1" Then
Dim wp As WebPart = DeclarativeCatalogPart1.GetWebPart(c)
wp.AuthorizationFilter = "admin"
End If
Next
'************************************************************
'Here call OnAuthorizeWebPart="AuthorizeWebParts" to refresh?
'************************************************************
End Sub
-----------------------------------------------------------------------------------------------------
Default.aspx
<asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" runat="server"/>
<WebPartsTemplate>
<uc1:Announcement title="Announcement" runat="server" />
</WebPartsTemplate>
</asp:DeclarativeCatalogPart>
-----------------------------------------------------------------------------------------------------
MyMaster.master
<asp:WebPartManager OnAuthorizeWebPart="AuthorizeWebParts" runat="server"> </asp:WebPartManager>
-----------------------------------------------------------------------------------------------------
MyMaster.master.vb
Protected Sub AuthorizeWebParts(ByVal sender As Object, ByVal e As WebPartAuthorizationEventArgs)
' If no roles are set, simply exit
If String.IsNullOrEmpty(e.AuthorizationFilter) Then
Return
End If
Dim rolesArray As String() = e.AuthorizationFilter.Split(New Char() {";"c})
' Assume the user does not have access to the web part
e.IsAuthorized = False
' Loop until the first role that allows the user access to the
' web part is encountered.
For Each roleStr As String In rolesArray
roleStr.Trim() '** I predefined the Session("Role")="user" in page_load for testing purpose **
If roleStr = Session("Role") Then
' the user has the rights, so authorize them
e.IsAuthorized = True
Exit For
End If
Next roleStr
End Sub