Custom Block List Property
j

johnkhigginson

over 1 year ago
I have a custom blocklist property as part of a document type. It's very simple and only accepts one block component type. I am trying to access this property in my code. While following the umbraco documentation here: https://docs.umbraco.com/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/block-editor/block-list-editor, It tells me it returns an IEnumerable. On that same page, it says that I can pull the value as that or BlockListModel... but with either, it returns null.
if (content.HasProperty("locations"))
{
    var locations = content.GetValue<BlockListModel>("locations");
    (or)
    var locations = content.GetValue<IEnumerable<BlockListItem>>("locations");
    ...
}
If I pull the value as a string or dynamic object, it will show as:
{"layout":{"Umbraco.BlockList":[{"contentUdi":"umb://element/74437d1928534a9287430056e140b99b"},{"contentUdi":"umb://element/382ddba6783948b28696798b3b6dad16"}]},"contentData":[{"contentTypeKey":"0285ad7f-763f-4bc5-80be-45f85f8a39e6","udi":"umb://element/74437d1928534a9287430056e140b99b","city":"Colville","stateA":"[\"WA\"]","name":"Colville Toyota"},{"contentTypeKey":"0285ad7f-763f-4bc5-80be-45f85f8a39e6","udi":"umb://element/382ddba6783948b28696798b3b6dad16","stateA":"[\"OR\"]","name":"Coos Bay Toyota","city":"Coos Bay"}],"settingsData":[]}
In converting to the BlockListModel, it has to be erroring causing it to return null; right? I need to pull the values this way because I am using those values to calculate other properties and then save that property to the document. Anyone running into this or have a solution? Is this enough info? I feel like I've tried quite a bit without success.
Issues with handling Save and Publish events in Umbraco - Need Help!
b

baristaner

over 1 year ago
Hello everyone, I am encountering some challenges with handling Save and Publish events in Umbraco, specifically using SaveAndPublishHandler class. Here are the details of my issue: **Problem Description**: I have implemented a SaveAndPublishHandler class in Umbraco to handle Saved and Published events for content items. The goal is to send an HTTP POST request to an external endpoint whenever content is saved or published with a specific ParentId (in my case, ParentId 1249). *Code : *
c#
        public SaveAndPublishHandler(IContentService contentService)
        {
            _contentService = contentService;
        }

        public void Initialize()
        {
            ContentService.Saved += ContentService_Saved;
        }

        public void Terminate()
        {
            ContentService.Saved -= ContentService_Saved;
        }

        private void ContentService_Saved(IContentService sender, SaveEventArgs<IContent> e)
        {
            foreach (var content in e.SavedEntities)
            {
                if (content.ParentId == 1249)
                {
                    var dataToSend = new { ContentId = content.Id, Title = content.Name };
                    var json = Newtonsoft.Json.JsonConvert.SerializeObject(dataToSend);
                    var contentToSend = new StringContent(json, Encoding.UTF8, "application/json");

                    using (var httpClient = new HttpClient())
                    {
                        var endpointUrl = "http://localhost:65137/umbraco/surface/UpdateApprovedAccount/UpdateApprovedAccountV2"; 

                        var response = httpClient.PostAsync(endpointUrl, contentToSend).Result;

                        var responseContent = response.Content.ReadAsStringAsync().Result;
                    }
                }
            }
        }
Composing :
c#
public void Compose(Composition composition) {
composition.Components().Append<SaveAndPublishHandler>();
}
Umbraco hosted in Azure is showing a lot of Cryptographic warnings in the log
c

CarlCod_es

over 1 year ago
We've got Umbraco hosted in Azure, in a load-balanced environment with deployment slots. We're seeing a lot of warnings in the logs. Umbraco Version 13.0.1 W : Error unprotecting the session cookie. Stack Trace : System.Security.Cryptography.CryptographicException: The key {078a31d2-3d8c-4b43-baeb-a639524b05c5} was not found in the key ring. For more information go to https://aka.ms/aspnet/dataprotectionwarning at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status) at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[] protectedData) at Microsoft.AspNetCore.Session.CookieProtection.Unprotect(IDataProtector protector, String protectedText, ILogger logger) We also see a rare instance of an error, but this seems much less frequent Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException: The antiforgery token could not be decrypted. Stacktrace : System.Security.Cryptography.CryptographicException: The key {84cea658-5bcd-439a-b175-d1c4bb7956f7} was not found in the key ring. For more information go to https://aka.ms/aspnet/dataprotectionwarning at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status) at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[] protectedData) at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(String serializedToken) --- End of inner exception stack trace --- at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(String serializedToken) at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery.GetCookieTokenDoesNotThrow(HttpContext httpContext) Anyone seen this issue, or similar?
Rebuild examine index fail, cannot deserialize the current JSON array
r

Rasolo

over 1 year ago
I get an error when trying to rebuild the examine index (umbraco 12) this is a new issue from upgrading from 8 to 12. Any advice in solving? Error message: Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Umbraco.Cms.Core.Models.Blocks.BlockValue' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly. To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array. Path '', line 1, position 1. at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureArrayContract(JsonReader reader, Type objectType, JsonContract contract) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newto at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items) at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source) at Umbraco.Cms.Infrastructure.Examine.ContentIndexPopulator.IndexAllContent(Int32 contentParentId, Int32 pageIndex, Int32 pageSize, IReadOnlyList`1 indexes) at Umbraco.Cms.Infrastructure.Examine.ContentIndexPopulator.PopulateIndexes(IReadOnlyList`1 indexes) at Umbraco.Cms.Infrastructure.Examine.IndexPopulator.Populate(IIndex[] indexes) ...