Pop Quiz: WebPart.AuthorizationFilter
Categories
In ASP.NET 2.0 you can assign a string called an AuthorizationFilter to a WebPart, then inspect it's value at runtime to decide whether or not to display a web part for a given user.
If I create a static web part like so...
<asp:WebPartZone ID="WebPartZone1" runat="server">
<ZoneTemplate>
<wp:CustomWeatherPart
id="CustomWeatherPart1"
AuthorizationFilter="DomainUser"
runat="server"
title="Today's Weather" />
</ZoneTemplate>
</asp:WebPartZone>
And add a dynamic part like this:
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
CustomWeatherPart part = new CustomWeatherPart();
part.AuthorizationFilter = "Administrator";
// Adds a custom web part to zone 1...
WebPartManager1.AddWebPart(
part,
WebPartZone1,
WebPartZone1.WebParts.Count
);
}
And then wire up the AuthorizeWebPart event handler like so:
protected override void OnInit(EventArgs e) {
base.OnInit(e);
WebPartManager1.AuthorizeWebPart +=
new WebPartAuthorizationEventHandler(WebPartManager1_AuthorizeWebPart);
}
How many times will my event handler get called for 1 page request? 0, 1, or 2? Why?
What about if I move the event handling wire-up code back to OnPreInit?