Posts

Showing posts from 2021

New Patch method in Service API 5.5.0

Image
  As you might know that we have API for these methods: Get, Post, Put and Delete but in some cases when you use the Put method it would re-add the whole property and make some values wiped (for example: Shipping Address). So we introduced a new Patch API to handle that case in the release of Service API 5.5.0 https://world.optimizely.com/support/bug-list/bug/COM-13687 For the usage, everything would be the same as Put method, you just need to change your code/tool to use Patch method:

Samesite cookie not working on DXP

Image
As the previous post related to Samesite cookie: https://khanhpham2411.blogspot.com/2020/11/samesite-cookie-login-troubleshooting.html It could work just fine in your local environment but when deployed to DXP the workaround using rewrite rule seem not working anymore. It might be the different .net version installed between DXP and local. Time to try some coding 🙂 Fortunately, I found a post really helpful: https://devblogs.microsoft.com/aspnet/upcoming-samesite-cookie-changes-in-asp-net-and-asp-net-core/ Then implement it with Episerver style: 1. Make sure you are targeting project with .NET 4.7.2  and upgraded Microsoft.Owin 4.1.0 2. Add this class to the Commerce Manager site using   Microsoft . Owin ; using   Microsoft . Owin . Infrastructure ; namespace   EPiServer . Reference . Commerce . Manager {    public   class   SameSiteCookieManager  :  ICookieManager   {      private   readonly ...

Impersonate user in Episerver

 TLDR: You can use this file: https://github.com/KhanhPham2411/Episerver-util-aspx/blob/main/impersonate.aspx Put it on your website root folder, then fill in the user name to impersonate (or search for it first if you are not sure about the user name) Background: Sometime that you might need to log in multiple users to test the personalization behavior but forgot the password or lazy to enter it :)) It would be great to just impersonate by fill in the user name. And fortunately, we can easily done it by using Episerver UI provider. First we need to find the user by name to see if it exist: userProvider.FindUsersByName(userName, 0, 1, out totalRecord).FirstOrDefault(); But we can't actually sign in without the password, so a hack used to reset password to  " P@ssw0rd " uiUserManager.ResetPassword(user, password); Finally, time to sign in uiSignInManager.SignIn(user.ProviderName, user.Username, password); Detail code could be found here:   https://github.com/KhanhPham2411/...

Getting Started Serviceapi (include Commerce)

Image
Installation 1. Install via nuget Episerver.ServiceAPI (or Commerce) 2. Update-Epidatabase to prevent this error 3. If we are using identity authorization: (add this in Startup) app.UseServiceApiIdentityTokenAuthorization<ApplicationUserManager<SiteUser>, SiteUser>(); 4. Disable ssl and maphttpattributeroutes (there might be an error "A route named 'MS_attributerouteWebApi' is already in the route collection") <add key="episerver:serviceapi:requiressl" value="false" /> <add key="episerver:serviceapi:maphttpattributeroutes" value="false" /> Note:  Do NOT remove maphttpattributeroutes of the site => as it might cause issue with Dependency Resolver Testing get token get relations http://localhost:52244/episerverapi/commerce/entries/36127195/entryrelations import assets =>  https://stackoverflow.com/questions/16015548/tool-for-sending-multipart-form-data-request => don't check Content-Type Listi...