Partager via


How to hide “Site Collection Administrators” link from settings toolbar menu of Out-of-the-Box User.aspx page (_layouts/user.aspx).

Option1 : Using a custom HttpModule to redirect to a custom-mngsiteadmin page. This approach ensures :

The OOB page isn’t accessible, even if users put the actual url (layouts/mngsiteadmin.aspx") in the browser and try accessing it.

Is easy to implement and supported.

The following sample approach can be tested :

<Sample-Code>

public class MasterPageModuleHandler : IHttpModule

    {

public void Init(HttpApplication context)

        {

            context.BeginRequest += new EventHandler(context_BeginRequest);

        }

void context_BeginRequest(object sender, EventArgs e)

        {

// throw new Exception("The method or operation is not implemented.");

            HttpApplication oApp = (HttpApplication)sender;

if (oApp.Request.RawUrl.Contains("/_layouts/mngsiteadmin.aspx"))

            {

                oApp.Response.Redirect(oApp.Request.RawUrl.Remove(oApp.Request.RawUrl.LastIndexOf("/")) + "/custom/SfMngSiteAdmin.aspx");

            }

        }

public void Dispose()

        {

        }

    }

</Sample-Code>

1. Build the Custom HTTP Module DLL and place it in the GAC

2. Assuming that a custom folder has been created under Layouts folder, ensure that custom-mngsiteadmin.aspx is present there.

3. Add the web.config entry for the custom HTTPModule in the config file of Web application

Find the HttpModules section in the web.config and add the following entry

<add name="HTTPModuleSPFileCache" type="HTTPModuleSPFileCache.CSetFileCache, HTTPModuleSPFileCache, Version=1.0.0.0, Culture=neutral, PublicKeyToken=<your key here>" />

4. Do an IISRESET.

Note: By putting a custom httpmodule in place, instead of normal 200 HTTP status, we get a HTTP 302 (Moved) and then a 200. No issues of performance hit have been reported , in using this approach, and you might want to test this one.

Option 2: Unlike Document Libraries\Lists, where the ToolBar is rendered through Templates defined in ControlTemplates.ascx, the Settings ToolBar for User.aspx is defined in the .aspx like below :

<SharePoint:FeatureMenuTemplate id="MenuTemplateSettings" LargeIconMode="TRUE" runat="server"

Location="Microsoft.SharePoint.User"

GroupId="SettingsMenu"

>

<SharePoint:MenuItemTemplate id="MenuItemSiteAdmins" runat="server" Text="<%$Resources:wss,people_siteadmins%>"

Description="<%$Resources:wss,people_siteadminsdescription%>"

ClientOnClickNavigateUrl="~site/_layouts/mngsiteadmin.aspx" Visible=false MenuGroupId="300" Sequence="100" />

MenuItemSiteAdmins is the ID of the the template responsible for rendering below menu :

clip_image002

So, to be able to override this behavior, I have to create a custom User.aspx page and override the link url to point to custom- mngsiteadmin.aspx page,Like below :

<SharePoint:FeatureMenuTemplate id="MenuTemplateSettings" LargeIconMode="TRUE" runat="server"

Location="Microsoft.SharePoint.User"

GroupId="SettingsMenu"

>

<SharePoint:MenuItemTemplate id="MyMenuItemSiteAdmins" runat="server" Text="<%$Resources:wss,people_siteadmins%>"

Description="<%$Resources:wss,people_siteadminsdescription%>" ClientOnClickNavigateUrl="~site/_layouts/custommngsiteadmin.aspx" Visible=true MenuGroupId="300" Sequence="100" />

So, modifying ClientOnClickNavigateUrl and Visible both  - does the trick.

Next step would be to correct all places where user.aspx appears, to actually point to custom user.aspx. (As I cannot modify OOB User.aspx, I basically have to create a custom copy of it, and then

Correct all those menu-items\links  which point to User.aspx)

Two of such places ,that I can enumerate are :

1. Site Permissions link in QuickLaunch on People.aspx

clip_image004

2. Site Permissions link in QuickLaunch on  groups.aspx

Just as an e.g, to add custom User.aspx to People.aspx – we again have to create a custom People.aspx, and replace this line :

<asp:MenuItem Text="<%$Resources:wss,people_sitepermissions%>" NavigateUrl="user.aspx"/>

With :

<asp:MenuItem Text="<%$Resources:wss,people_sitepermissions%>" NavigateUrl="cuser.aspx"/>

So, the approach requires wide customization and there is no easy way to achieve this (none- as easy as Option1 above).