Search code examples
sitecorepage-editor

Disable designing role programmatically


I was wondering if there was any way to toggle/disable designer role from code. The desired effect from command: webedit:toggledesigncapability.

Image of command in page editor:

How can I toggle the designing capabilities from code?


Solution

  • Code below toggles the state of this setting for the current user. It should work for you or at least point you in the right direction. I didn't have time to test it so you need to do this on your own. Remember to refresh to page after you executed the code:

    string key = "/Current_User/Page Editor/Capability/design";
    if (Sitecore.Web.UI.HtmlControls.Registry.GetString(key, "on") == "on")
    {
        Sitecore.Web.UI.HtmlControls.Registry.SetString(key, "off");
    }
    else
    {
        if (WebEditUtil.CanDesignItem(Sitecore.Context.Item))
        {
            Sitecore.Web.UI.HtmlControls.Registry.SetString(key, "on");
        }
    }