Skip Navigation Links / Posts / Post
Search site. 
Powered by Google
Darren Neimke (Me)

My Book

Readify

">ASP.NET MVP


Interesting Portals 

NetVibes
This portal feels similar to PageFlakes in many ways but I love their gallery. They also have a feature whre certain chrome elements only become visible when you hover over the web part.

Xtra
A New Zealand news portal. I especially liked the content rotator web part at the top of the middle row. Seems like a nice way to allow a user to browse through data.

 

Posts Archive 

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?

posted 11/2/2005 3:04:07 PM

 

Comments:

There are no comments to display for this post.

 

Comments are currently disabled for this post.