Home » Microsoft TechnologiesRSS

"Show ribbon" default

Answer:

With a little reflection, I found  a solution that works in my scenario:

publicclass RibbonControl : WebControl
  {
    protectedoverridevoid OnPreRender(EventArgs e)
    {
      ToggleConsoleOn();
      base.OnPreRender(e);
    }

    internalstaticvoid ToggleConsoleOn()
    {      
      var cookieName = CookieName;
      var current = HttpContext.Current;
      if (!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";
      }
    }

    internalstaticstring CookieName
    {
      get
      {
        return ("ConsoleVisible" + ContextualSite.ID.ToString());
      }
    }

    publicstatic SPSite ContextualSite
    {
      get
      {
        return SPContext.GetContext(HttpContext.Current).Site;
      }
    }
 
 
 


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter