Posts

“An item with the same key has already been added. Key: PageDescription”

Image
  “An item with the same key has already been added. Key: PageDescription ” System.ArgumentException: at System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Collections.Generic.Dictionary`2.TryInsert (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Mediachase.MetaDataPlus.Configurator.MetaObjectDB.LoadMetaObjectData (Mediachase.MetaDataPlus, Version=14.15.2.0, Culture=neutral, PublicKeyToken=41d2e7a615ba286c) at Mediachase.MetaDataPlus.Internal.CatalogMetaObjectRepository.DoLoadFromDb (Mediachase.MetaDataPlus, Version=14.15.2.0, Culture=neutral, PublicKeyToken=41d2e7a615ba286c) We could use this query to find the content that caused the error: SELECT TOP(1000) ObjectId, MetaFieldName, COUNT(*) AS Count FROM [dbo].[CatalogContentProperty] Where MetaFieldName = ' PageDescription ' GROUP BY ObjectId, MetaFie...

Remove metafield from product content

Even when you remove the code of the  meta field from product content ,  it's still there in the database.  So we need the scripts to complete removing them in both Commerce and CMS: For Commerce: DECLARE @MetaFieldId INT = 80  DELETE FROM MetaDictionary WHERE MetaFieldId = @MetaFieldId  DELETE FROM CatalogContentProperty WHERE MetaFieldId = @MetaFieldId  DELETE FROM ecfVersionProperty WHERE MetaFieldId = @MetaFieldId  DELETE FROM MetaClassMetaFieldRelation WHERE MetaFieldId = @MetaFieldId  DELETE FROM MetaField WHERE MetaFieldId = @MetaFieldId  EXEC mdpsp_sys_ClearMetaAttribute @MetaFieldId, 2 For CMS: exec netPropertyDefinitionDelete @PropertyDefinitionID=2699     If the meta field is not completely removed, the meta field will be re-creating/re-appearing in `tblPropertyDefinition` in CMS when you restart the site: declare @p1 int  set @p1=2702  declare @p16 int  set @p16=7  declare @p17 int  set @p17=NULL...

DnSpy: Getting Started

Image
  You can setup the website in your local environment and use the DnSpy tool to debug to any library   without its source code.    Please refer the belows steps to know how to debug with DnSpy: 1- Download the dnSpy ( https://github.com/dnSpy/dnSpy/releases/tag/v6.1.8 )  to your computer and  Run the dnSpy.exe as Administrator 2- Select Debug > Attach to Process, choose  w3wp.exe or iisexpress.exe 3- Select Debug > Windows > Modules tab window, search the customer DLL filename and copy the file path. This path is the actual the assembly runs in IIS website. Depend on your case, choose the *.dll file 4- Open this Dll file path in dnSpy, go to the class / method we want to debug () 5- Set the Breakpoint and start Debug like in the Visual Studio

Episerver ServiceAPI: Create a custom endpoint

Image
In some cases, you uploaded an asset through Service API. And then you want to update its properties later. You can create a custom endpoint to implement it and we want to reuse the authentication, routing  of ServiceAPI: https://github.com/KhanhPham2411/Episerver-util-api/blob/master/service-api/ItemAssetController using EPiServer.ServiceApi.Configuration; using EPiServer.ServiceApi.Validation; using EPiServer.ServiceApi.Commerce.Controllers.Catalog; using ControllerBase = EPiServer.ServiceApi.Commerce.Controllers.Catalog.ControllerBase; using AuthorizePermissionAttribute = EPiServer.ServiceApi.Configuration.AuthorizePermissionAttribute; using EPiServer.ServiceApi.Commerce; using Foundation.Features.Media; using EPiServer.DataAccess; using EPiServer.Security; using System.Configuration.Provider; namespace Foundation.Custom {     [Route("episerverapi/commerce")]     [RequireHttpsOrClose]     [ValidateReadOnlyMode(AllowedVerbs = HttpVerbs.Get)]   ...

Episerver Commerce 14: Menu access

Image
It's the CommerceUIMenuProvider that controls the general menu access, you can configure it in appsettings.json: (Compared to Commerce 13: <add name="CatalogManagers" type="EPiServer.Security.MappedRole, EPiServer.Framework" roles="CommerceSales" mode="Any" />) Common roles are: WebAdmins, WebEditors... In case you want to create an access group that enables access to only: Customers Order management Reports As the image below: we could use ReportManagers, CustomerManagers, CustomerServiceRepresentatives:  

Episerver Commerce Manager access: Permission for Functions

Image
  To access Commerce Manager site, we need grant access core:mng:login To access Payment: 3.  Allowing access permision to Order Management left side tabs Notes: The virtual roles only affect front-end site not Commerce manager The functions only affect Commerce Manager not front-end site

Episerver ServiceAPI: Example of how-to properly call the media upload

Image
For the example of how-to properly call the media upload, you can refer to my Postman collection: https://github.com/KhanhPham2411/EpiserverAPI_PostmanCollection/blob/main/ServiceAPI/ServiceAPI_Collections.json   For the detail steps: Copy the raw content to Postman: https://raw.githubusercontent.com/KhanhPham2411/EpiserverAPI_PostmanCollection/main/ServiceAPI/ServiceAPI_Collections.json   2. Get ServiceAPI NetCore Token   3. Post to Assets/Import Example media file: https://github.com/KhanhPham2411/EpiserverAPI_PostmanCollection/blob/main/ServiceAPI/01-CreateMediaWithBlob.zip 4. To verify your import is working, use that task id to get task log: