Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Hide Master Page elements based on users domain name

  Asked By: Dario    Date: Mar 26    Category: Sharepoint    Views: 4489

On my master page I have some elements that need to be 'hidden' if a
user (this is an Intranet site, they'll all be authenticated) is in a
particular domain. Not sure how to accomplish this. Can anyone
provide some guidance?



5 Answers Found

Answer #1    Answered By: Linda Mason     Answered On: Mar 26

Do you use Visual Studio when you work with your SharePoint solution?

Answer #2    Answered By: Hans Weiss     Answered On: Mar 26

No - but I can if that will help. I've just been doing SP Designer stuff so
far. Any ideas?

Answer #3    Answered By: Alison West     Answered On: Mar 26

Although you can do this with custom code you want to be very careful if you
try. Security trimming items in the master  page, as opposed to let the items
security trim themselves, will tend to break page  and fragment caching of the
master page. That can lead to each page taking 30-45 seconds to load everytime.
I don't recommend it. What kinds of elements  do you want to hide?

Answer #4    Answered By: Freddy Heath     Answered On: Mar 26

I would solve it the following way:

Create a Web Application project in Visual Studio 2005 - you need to install the
Web Application Project Template, is included in SP1 for VS

Add a reference to Microsoft.SharePoint dll in your project

Create a master  page - you then get a code behind file

Copy the code from "YourCurrent.master" to "YourNew.master".

Surround the code you want to hide  in your master with an <asp:PlaceHolder
id="yourPlaceHolder" runat="server">

Add a page-init even in the code-behind

In your page-init event you check if
Microsoft.SharePoint.SPContext.Current.Web.CurrentUser.LoginName starts with
your domainname + \, if it does you hide your elements  by setting
yourPlaceHolder.Visible = false

Build your project and copy your dll to the gac - you can put it in the webapp
bin folder also.

Register at safecontrol in web.config

Enter the assembly to the compilation tag area in the web.config - if you chose
to put your assembly in the gac

Depending on what masterpage you want to change there are different ways:

Upload your new master in "_catalgos/masterpage" gallery or replacing the old
(then you have to build it with the same name of course)

Replace the master in the filesystem (this is not recommended when upgrading
will overwrite your changes) - but sometimes I think it can be necessary (just
make sure you take a copy of the original.

If you have chosen a new master and uploaded it to the masterpagegallery you
have to point it out in your site  - settings - masterpage - change masterpage

This is a simple description

If you want a more precise one let me know

Answer #5    Answered By: Joanna Dixon     Answered On: Mar 26

If the elements  to be hidden  don't pose a security threat then you can
probably use javascript to show or hide  the elements depending on which
domain you came from. The javascript will use cookies to enable
persistence of state between page  calls once you're on the new domain.
We've used this techninque to show or hide our own DIVs on a master
page depending on the originating domain  - i've never tried it on a
microsoft supplied master-page element. I suspect you'll want to wrap
those elements in a DIV tag with your own ID to make them easiewr to
work with in javascript if you do go down this route.

Didn't find what you were looking for? Find more on Hide Master Page elements based on users domain name Or get search suggestion and latest updates.