Action List


The following table lists the types of actions included in this version of Page Action Web Part.

Action Type Description
Access is denied Re-directs the user to the standard SharePoint "Access Denied" page
Not found Displays the default 404 error message (Not found) to the user
Redirect to Re-directs the user to a specific Web page
Transfer to an error page Re-directs the user to the built-in error page provided by Windows SharePoint Services
Show contents Shows formatted text, tables, hyperlinks, and images to a Web Part Page, together with ASP.NET controls and !$-expressions
Hide page elements Hides page elements such as Site Actions menu, Quick Launch menu, Recycle Bin, etc.
Track access to the page This documentation is not ready yet
Manage Web Parts Hides or makes visible the other Web Parts hosted on the page

For every action is reported a detailed description and examples of use via code (C #). Note that in all the examples below you'll need to add a reference to Evolution.dll to be able to compile the code.


Access is Denied action

This action redirects the user to the standard SharePoint "Access Denied" page.

Standard SharePoint "Access Denied" page
This action requires the specification of a condition associated.

Similarly to what can happen by making use of actions Not found and Transfer to an error page, this action may be used to manage the declarative security of the Web page: by choosing as condition the assertion Current user, for example, you can ensure that all users who do not belong to a particular user group (SharePoint or Active Directory) automatically receive an access denied message.

"Access is Denied" action
The following code samples show how to use the Page Action Web Part to redirect all users who do not belong to the SP_GROUP_NAME SharePoint group to the standard SharePoint "Access Denied" page.

using Evolution.UI.WebParts;
using Evolution.Security;

SPFile file = ...
                    
using (SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
       PageActionWebPart wp = new PageActionWebPart();
       wp.ID = "PageActionWebPart1";
       wp.ErrorNotificationMode = ErrorNotificationMode.Always;
       wp.Action = new AccessIsDeniedAction();
                                        
       CurrentUserAssertion cua = new CurrentUserAssertion();
       cua.Operator = CurrentUserOperator.DoesNotBelongTo;
       cua.SecurityEntity = new SecurityEntity("", "", "SP_GROUP_NAME");
       wp.Condition.Add(cua);

       manager.AddWebPart(wp, "Left", 1);
}

Not found action

This action displays the default 404 error message (HTTP 404 Not Found) to the user. This action requires the specification of a condition associated.

Similarly to what can happen by making use of actions Access is denied and Transfer to an error page, this action may be used to manage the declarative security of the Web page: by choosing as condition the assertion Current user, for example, you can ensure that all users who do not belong to a particular user group (SharePoint or Active Directory) automatically receive a 404 (page not found) error message.

The following code samples show how to use the Page Action Web Part to show the 404 error page to any users who do not belong to the SP_GROUP_NAME SharePoint group.

using Evolution.UI.WebParts;
using Evolution.Security;

SPFile file = ...
                    
using (SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
       PageActionWebPart wp = new PageActionWebPart();
       wp.ID = "PageActionWebPart1";
       wp.ErrorNotificationMode = ErrorNotificationMode.Always;
       wp.Action = new NotFoundAction();
                                        
       CurrentUserAssertion cua = new CurrentUserAssertion();
       cua.Operator = CurrentUserOperator.DoesNotBelongTo;
       cua.SecurityEntity = new SecurityEntity("", "", "SP_GROUP_NAME");
       wp.Condition.Add(cua);

       manager.AddWebPart(wp, "Left", 1);
}

Redirect to action

You can use this action whenever you want to direct the user to a different page. For example, you might create a landing page that determines the user's application role membership, and based on that information you can redirect them to an appropriate page. Or, based on the contents of a query string issued by the user's browser, you might redirect them to a page that can process the query string.

The action supports parameters that enable you to specify the URL of the target page (as plain text or using a !$-expression) and the redirect behavior. This action requires the specification of a condition associated.

"Redirect to" action
The possible redirect behaviors are the following:
  • Direct, the user will be redirected to the specified URL.
  • Relative to layouts, the specified URL is considered relative to the ´_layouts´.
  • Use Source, the URL to which the user is redirected will be read from the querystring of the original request. The new URL will be the value of one of these querystring parameters: Source, NextUsing or NextPage. If none of these parameters has a value, will be used the specified URL. If, however, has not been specified any URL (optional with this method of redirect), the redirect will not happen.
The following code samples show how to use two Page Action Web Parts to redirect each user to a particular Web page according to his membership to the "Members" or "Owners" SharePoint groups of the Web site.

using Evolution.UI.WebParts;
using Evolution.Security;

SPFile file = ...
                    
using (SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
       PageActionWebPart wp = new PageActionWebPart();
       wp.ID = "PageActionWebPart1";
       wp.ErrorNotificationMode = ErrorNotificationMode.Always;
       wp.Action = new RedirectToAction("Pages/WelcomeToOwners.aspx", RedirectMode.Direct);
                                   
       CurrentUserAssertion cua = new CurrentUserAssertion();
       cua.SecurityEntity = new SecurityEntity("", "", web.AssociatedOwnerGroup.Name);
       cua.Operator = CurrentUserOperator.BelongsTo;
       wp.Condition.Add(cua);

       manager.AddWebPart(wp, "Left", 1);

       wp = new PageActionWebPart();
       wp.ID = "PageActionWebPart2";
       wp.ErrorNotificationMode = ErrorNotificationMode.Always;
       wp.Action = new RedirectToAction("Pages/WelcomeToMembers.aspx", RedirectMode.Direct);

       cua = new CurrentUserAssertion();
       cua.SecurityEntity = new SecurityEntity("", "", web.AssociatedMemberGroup.Name);
       cua.Operator = CurrentUserOperator.BelongsTo;
       wp.Condition.Add(cua);

       manager.AddWebPart(wp, "Left", 2);
}

Transfer to an error page action

This action redirects the user to the built-in error page provided by Windows SharePoint Services.

"Transfer to an error page" action
The action requires the specification of a condition associated and accepts a parameter for the error message to be displayed. The error message can be a simple text or a !$-expression.

"Transfer to an error page" tool pane
Similarly to what can happen by making use of actions Access is denied and Not found, this action may be used to manage the declarative security of the Web page: by choosing as condition the assertion Current user, for example, you can ensure that all users who do not belong to a particular user group (SharePoint or Active Directory) are automatically redirected to the SharePoint error page.

The following code samples show how to use the Page Action Web Part to show the error page to all users not belonging to the SP_GROUP_NAME SharePoint group. The error message specified for the action uses a !$-expression to get the current user name.

using Evolution.UI.WebParts;
using Evolution.Security;

SPFile file = ...
                    
using (SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
       PageActionWebPart wp = new PageActionWebPart();
       wp.ID = "PageActionWebPart1";
       wp.ErrorNotificationMode = ErrorNotificationMode.Always;
       wp.Action = new TransferToErrorPageAction("The current user account (!$ CurrentUser.LoginName $) does not have access to this page.");
                                        
       CurrentUserAssertion cua = new CurrentUserAssertion();
       cua.Operator = CurrentUserOperator.DoesNotBelongTo;
       cua.SecurityEntity = new SecurityEntity("", "", "SP_GROUP_NAME");
       wp.Condition.Add(cua);

       manager.AddWebPart(wp, "Left", 1);
}

Show contents action

This action can be used to add formatted text, tables, hyperlinks, and images to a Web Part Page, similarly the Content Editor Web Part. Unlike the Content Editor, however, this action allows the user to mix ASP.NET controls and !$-expressions to the text.
"Show contents" action
There are three ways to add objects to the content displayed by the action:
  • Rich Text Editor. You can use the Rich Text Editor to type formatted content automatically without prior knowledge of HTML syntax. The Rich Text Editor accepts !$-expressions but can not be used to insert ASP.NET controls. Choose the Source Editor to add ASP.NET controls.
Rich Text Editor
  • Source Editor. Using this editor, you can enter or modify HTML source code, !$-expressions or ASP.NET controls.
Source Editor
  • Content Link. Instead of editing content, you can link to existing content by entering a hyperlink to a text file containing HTML source code, !$-expressions or ASP.NET controls. You can use an absolute URL or a relative URL. In any case, the URL can contain !$-expressions.
The process of rendering the contents of the action, goes through two stages of parsing:
  1. !$-expressions that may be present in the text are evaluated,
  2. The content resulting from the first step is then subjected to the parsing of any ASP.NET controls by using the method ParseControl of the class TemplateControl. The text cannot contain any code, because the method ParseControl never causes compilation.
The result of the two stages process is always a Control object. whose rendering is the final content displayed by the action.

The following code must be added through the Source Editor and shows how to use objects of type ASP.NET Panel and !$-expressions to render different information depending on the belonging of the current user to one of the main groups of the site (Visitors, Members, Owners):

<asp:Panel Runat="server" ID="Panel1" Visible="!$ CurrentWeb.AssociatedVisitorGroup.ContainsCurrentUser $">
      The current user is a Visitor.
</asp:Panel>

<asp:Panel Runat="server" ID="Panel2" Visible="!$ CurrentWeb.AssociatedMemberGroup.ContainsCurrentUser $">
      The current user is a Member.
</asp:Panel>

<asp:Panel Runat="server" ID="Panel3" Visible="!$ CurrentWeb.AssociatedOwnerGroup.ContainsCurrentUser $">
      The current user is a Owner.
</asp:Panel>
The following code samples show how to use the Page Action Web Part to generate a report page on the current user data through the action "Show contents" and the use of !$-expressions and ASP.NET controls.

using Evolution.UI.WebParts;

SPFile file = ...
                    
using (SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
        string text = @"
            <table cellspacing=""4"">
                <tr><td valign=""top""><b>Name</b></td><td>!$ CurrentUser.Name $</td></tr>
                <tr><td valign=""top""><b>Login</b></td><td>!$ CurrentUser.LoginName $</td></tr>
                <tr><td valign=""top""><b>E-mail</b></td><td><a href=""mailto:!$ CurrentUser.Email $"">!$ CurrentUser.Email $</a></td></tr>
                <tr><td valign=""top""><b>Notes</b></td><td>!$ CurrentUser.Notes $</td></tr>
                <tr><td valign=""top""><b>Is administrator?</b></td><td>!$ if(CurrentUser.IsSiteAdmin, ""yes"", ""no"") $</td></tr>
                <tr><td valign=""top""><b>Is owner?</b></td><td>!$ if(CurrentWeb.AssociatedOwnerGroup.ContainsCurrentUser, ""yes"", ""no"") $</td></tr>
                <tr><td valign=""top""><b>Is member?</b></td><td>!$ if(CurrentWeb.AssociatedMemberGroup.ContainsCurrentUser, ""yes"", ""no"") $</td></tr>
                <tr><td valign=""top""><b>Is visitor?</b></td><td>!$ if(CurrentWeb.AssociatedVisitorGroup.ContainsCurrentUser, ""yes"", ""no"") $</td></tr>
                <tr>
                    <td valign=""top""><b>Groups</b></td><td>
                    !$
                      if(CurrentUser.IsSiteAdmin or CurrentWeb.AssociatedOwnerGroup.ContainsCurrentUser, 
                        concat(CurrentUser.Groups, ""group"", 
                              escape(""'<a href=' + CurrentWeb.Url + '/_layouts/people.aspx?MembershipGroupId=' + group.ID + '>' + group.Name + '</a><br />'"")
                        ), 
                        concat(CurrentUser.Groups, ""group"", 
                              escape(""group.Name + '<br />'"")
                        )
                      )
                     $
                    </td>
                </tr>
            </table>";

        PageActionWebPart wp = new PageActionWebPart();
        wp.ID = "PageActionWebPart1";
        wp.ErrorNotificationMode = ErrorNotificationMode.Always;
        wp.Action = new ShowContentsAction(text);
                                                      
        manager.AddWebPart(wp, "Left", 1);
}
The following code samples show how to load the contents of the action from a text file contained in the document library "Documents". The URL uses an !$-expression to dynamically obtain the full address of the Web site.

using Evolution.UI.WebParts;

SPFile file = ...
                    
using (SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
        ShowContentsAction sa = new ShowContentsAction();
        sa.Url = "!$ CurrentWeb.Url $/Documents/contents.txt";

        PageActionWebPart wp = new PageActionWebPart();
        wp.ID = "PageActionWebPart1";
        wp.ErrorNotificationMode = ErrorNotificationMode.Always;
        wp.Action = sa;
                                                      
        manager.AddWebPart(wp, "Left", 1);
}

Hide page elements action

This action hides one or more of the following elements of the Web page:

Description Element
Site Actions menu Site Actions menu
Quick Launch menu 1 Quick Launch menu
Recycle Bin link Recycle Bin
View All Site Content link "View All Site Content" link
Create Page Site Actions menu item "Create Page" menu item
Edit Page Site Actions menu item2 "Edit Page" menu item
Global navigation breadcrumb Global Navigation
Search box area Search Area
Main breadcrumb Breadcrumb

1 When the Quick Launch menu is hidden, the space occupied by the Web Parts of the page expands to the entire width of the page.
2 When the Edit Page menu item is hidden, the Show Page Editing Toolbar item is also hidden.

The following code samples show how to use the Page Action Web Part to hide unconditionally the Quick Launch menu and the Site Actions menu of the page.

using Evolution.UI.WebParts;

SPFile file = ...
                    
using (SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
        HidePageElementsAction hideAction = new HidePageElementsAction();
        hideAction.PageElements = PageElements.QuickLaunch | PageElements.SiteActions;

        PageActionWebPart wp = new PageActionWebPart();
        wp.ID = "PageActionWebPart1";
        wp.ErrorNotificationMode = ErrorNotificationMode.Always;
        wp.Action = hideAction;
                                                      
        manager.AddWebPart(wp, "Left", 1);
}
The property PageElements of the class HidePageElementsAction accepts a combination of one or more elements of the bit field PageElements, combined with a bitwise OR operation. The definition of PageElements is as follows:

namespace Evolution.UI.WebParts
{
    [Flags]
    public enum PageElements
    {
        None = 0,
        SiteActions = 1,
        QuickLaunch = 2,
        RecycleBin = 4,
        ViewAllSiteContent = 8,
        CreatePage = 16,
        EditPage = 32,
        GlobalNavigation = 64,
        SearchArea = 128,
        TitleBreadcrumb = 256,
    }
}

Manage Web Parts action

You can use this action to hide or make visible the other Web Parts hosted on the page. Similar to what is achieved by specifying the standard SharePoint Target Audiences for one or more Web Parts on a Web page, binding this action to an appropriate condition (complex as desired) imposes a rule of visibility / hiddenness to the selected Web Parts, a rule that can be far more complex than determining if the current user belongs to one or more groups of users.

"Manage Web Parts" action
To specify which Web Parts of the page show or hide, click the button Select Web Parts… to open the "Web Part list" dialog box, then mark the appropriate check boxes, selecting the action to be taken for each Web Part.

"Web Part list" dialog box
The following code samples show how to use the Page Action Web Part to show different Content Editor Web Parts depending on the belonging of the current user to one of the main groups of the site (Visitors, Members, Owners):

using Evolution.UI.WebParts;

SPFile file = ...
                    
using (SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
        XmlDocument xmlDoc;
        XmlElement xmlElement;

        ContentEditorWebPart visitorsCEWP = new ContentEditorWebPart();
        ContentEditorWebPart membersCEWP = new ContentEditorWebPart();
        ContentEditorWebPart ownersCEWP = new ContentEditorWebPart();

        // *** Visitors CEWP **********************************************
        visitorsCEWP.ID = "VisitorsCEWP";
        visitorsCEWP.Title = "Visitors";

        xmlDoc = new XmlDocument();
        xmlElement = xmlDoc.CreateElement("HtmlContent");
        xmlElement.InnerText = "<DIV><H2>Html content for Visitors.</H2></DIV>";                        
        
        visitorsCEWP.Content = xmlElement;
        
        manager.AddWebPart(visitorsCEWP, "Left", 0);

        // *** Members CEWP **********************************************
        membersCEWP.ID = "MembersCEWP";
        membersCEWP.Title = "Members";
        
        xmlDoc = new XmlDocument();
        xmlElement = xmlDoc.CreateElement("HtmlContent");
        xmlElement.InnerText = "<DIV><H2>Html content for Members.</H2></DIV>";
        
        membersCEWP.Content = xmlElement;                                                
        
        manager.AddWebPart(membersCEWP, "Left", 1);

        // *** Owners CEWP ***********************************************
        ownersCEWP.ID = "OwnersCEWP";
        ownersCEWP.Title = "Owners";

        xmlDoc = new XmlDocument();
        xmlElement = xmlDoc.CreateElement("HtmlContent");
        xmlElement.InnerText = "<DIV><H2>Html content for Owners.</H2></DIV>";

        ownersCEWP.Content = xmlElement;

        manager.AddWebPart(ownersCEWP, "Left", 2);

        // *** CurrentUser Assertions **********************************************
        CurrentUserAssertion cua1 = new CurrentUserAssertion();
        cua1.Operator = CurrentUserOperator.DoesNotBelongTo;
        cua1.SecurityEntity = new Evolution.Security.SecurityEntity("", "", web.AssociatedVisitorGroup.Name);

        CurrentUserAssertion cua2 = new CurrentUserAssertion();
        cua2.Operator = CurrentUserOperator.DoesNotBelongTo;
        cua2.SecurityEntity = new Evolution.Security.SecurityEntity("", "", web.AssociatedMemberGroup.Name);

        CurrentUserAssertion cua3 = new CurrentUserAssertion();
        cua3.Operator = CurrentUserOperator.DoesNotBelongTo;
        cua3.SecurityEntity = new Evolution.Security.SecurityEntity("", "", web.AssociatedOwnerGroup.Name);

        // *** PageActionWebPart1 **********************************************
        ManageWebPartsAction mwp = new ManageWebPartsAction();
        List<ManagedWebPart> mwpl = new List<ManagedWebPart>();
        mwpl.Add(new ManagedWebPart(visitorsCEWP.ClientID, true));    
        mwp.WebParts = mwpl.ToArray();
        
        PageActionWebPart wp = new PageActionWebPart();
        wp.ID = "PageActionWebPart1";
        wp.ErrorNotificationMode = ErrorNotificationMode.Always;
        wp.Action = mwp;
        wp.Condition.Add(cua1);

        manager.AddWebPart(wp, "Left", 3);

        // *** PageActionWebPart2 **********************************************
        mwp = new ManageWebPartsAction();
        mwpl = new List<ManagedWebPart>();
        mwpl.Add(new ManagedWebPart(membersCEWP.ClientID, true));   
        mwp.WebParts = mwpl.ToArray();

        wp = new PageActionWebPart();
        wp.ID = "PageActionWebPart2";
        wp.ErrorNotificationMode = ErrorNotificationMode.Always;
        wp.Action = mwp;
        wp.Condition.Add(cua2);

        manager.AddWebPart(wp, "Left", 4);

        // *** PageActionWebPart3 **********************************************
        mwp = new ManageWebPartsAction();
        mwpl = new List<ManagedWebPart>();
        mwpl.Add(new ManagedWebPart(ownersCEWP.ClientID, true));
        mwp.WebParts = mwpl.ToArray();

        wp = new PageActionWebPart();
        wp.ID = "PageActionWebPart3";
        wp.ErrorNotificationMode = ErrorNotificationMode.Always;
        wp.Action = mwp;
        wp.Condition.Add(cua3);

        manager.AddWebPart(wp, "Left", 5);
}

See also
  • Introduction to Page Action Web Part.
  • Project Description, for a more detailed overview.
  • Action list, ie this page.
  • Assertion list, to get information about the assertions that can be used to create a condition (this documentation is not ready yet).
  • !$-expressions, to learn how to use the expressions in Page Action Web Part.

Last edited Jun 1, 2010 at 3:30 PM by DavideLoria, version 131

Comments

No comments yet.