I'm trying to build a custom admin utility page which will add renderings to a page.
The action happens in an Ajax call and so the Sitecore.Context is unavailable.
I do have the pageItem
though.
LayoutField layoutField = new LayoutField(pageItem.Fields[FieldIDs.LayoutField]);
LayoutDefinition layoutDefinition = LayoutDefinition.Parse(layoutField.Value);
var contextDb = Sitecore.Context.Database;
DeviceDefinition deviceDefinition = layoutDefinition.GetDevice(Sitecore.Context.Device.ID.ToString());
In the above code, contextDb
is null & deviceDefition
throws an error because Sitecore.Context.Device
is null.
Is there a way to programmatically set the Sitecore.Context
or get it from the pageItem
.
Using Sitecore 9.3
Sitecore.Context.Database
just usepageItem.Database
. There is no way of getting the device from the request of admin page. Easiest way is to passdeviceId
to your ajax requestSitecore.Context.Device.ID
in thePage_Load
event of the aspx custom-admin-page. It is null. Should this page inherit from any other class. I have created many admin pages before that do item manipulations like create/update etc. But this is the first one that needsSitecore.Context
. Please suggest.