I have the following problem: the ribbon bar gets hidden by default for the users of a site collection, so they must enable it manually by using the "Show Ribbon" link on the site action menu.
This is only added noise for most of the user, and make the site unusable for user that cannot reach the "show ribbon" menu because they don't have access to the site action link.
I really hope that this behavior isn't the standard one (it would be very very lame if such).... so I am struggling in finding how to set the ribbon to stay open by default. Any idea?
EDIT:
Based on Oc3LoT answer about the limited access, I have made some more in-depth tests. It would seem that the ribbon starts closed for user that don't normally see the "site action" menu. In that case, the ribbon get hidden too (I remember reading somewhere that the site action link is actually IN the ribbon, or at last uses the same css classes) and the user won't have any way to display it.
This is indeed strange: if I navigate to a document lib the user has access to, the ribbon is displayed, but if I create a page with the out of the box document library web part the ribbon remains hidden - even if I select a file in the web part. This doesn't make much sense, so I am still wondering if this is standard behavior or if I am missing something somewhere...
NOTE: as a reference, this question Show Ribbon always to Visitors is indicating the same behavior/problem. Notice that this is not a duplicate. I am searching a way to always provide the show/hide functionality (at last when it is enabled in site setting), or at last make the ribbon visible by default (not always visible, I want user to hide it if they really want to).
Also, while a solution to the problem is indeed wanted, what I would really like is an explanation of what is the reason behind this misbehavior.
Almost found it. The show/hide ribbon buttons actually work by setting a cookie called ConsoleVisible[GuidOfTheSiteCollection]. After some attempt of setting it via JavaScript thru a content editor web part in the end I moved it to a control delegate built with a code based on this answer found on another site (link here).
I am posting the class code as a reference here, credit to the original finder. Notice that I had to make some minor editing to avoid some bad timing (now the logic runs OnLoad) in my solution.
public class SetRibbonDefaultVisibleControl : WebControl
{
protectedoverridevoid OnLoad(EventArgs e)
{
ToggleConsoleOn();
base.OnLoad(e);
}
internal static void ToggleConsoleOn()
{
var cookieName = CookieName;
var current = HttpContext.Current;
if (!current.Request.Cookies.AllKeys.Contains<string>(cookieName)
&&
!current.Response.Cookies.AllKeys.Contains<string>(cookieName))
{
current.Response.Cookies.Add(new HttpCookie(cookieName, "true"));
current.Response.Cookies[CookieName].Expires = DateTime.Now.AddYears(1);
current.Items[CookieName] = "true";
}
}
internal static string CookieName
{
get{ return ("ConsoleVisible" + ContextualSite.ID.ToString()); }
}
public static SPSite ContextualSite
{
get{ return SPContext.GetContext(HttpContext.Current).Site; }
}
}
Had originally posted this as an answer, but it seems that the cookie is totaly ignored for visitors. Basically if the site action menu is hidden the above doesn't work (image taken from the other post linked above, but it gives you the idea).
Now I am exploring yet another dungeon, (Master) sword in hand, to see if I can find the evil behind all this...
EDIT 2: I guess that I have found the class responsible for all the above.
Microsoft.SharePoint.Publishing.WebControls.ConsoleVisibleUtilities
Inside this class there are some method that seems to control the "console" visibility. Those method seems to depend on the "site action" menu visibility -> user permissions on the site. To cite 300 "This is madness!", but I guess that this kills any hope of displaying the ribbon via a codebehind script.
ConsoleVisibleUtilities
for me the problem is that the status bar is hidden even though the page is checked out to another user. Turns out that the check f(SPContext.Current.FileLevel != SPFileLevel.Published)
fails as the page is found out to not be checked out. I used your solution and it works flawlessly now - always have the status bar even if the page is checked out to another user.