Sitecore 10 – Asp.net core – exploring ModelBoundView

One of the big news within Sitecore 10 is the support for ASP.NET core Rendering SDK for dotnet core 3.1 (note that in November MS released .net 5 and hopefully Sitecore will update the support and starting kit for .net 5

Sitecore released a starter kit and I would suggest to check the following links to get you started with the environment configuration:

https://doc.sitecore.com/developers/100/developer-tools/en/walkthrough–using-the-getting-started-template.html

Anyway I wanted to give a simple explanation and breakdown of the ModelBoundView component that is the equivalent of the classic MVC ViewRendering exploring all the elements required to get your first ModelBoundView working.

Typically you would use a ModelBoundview when you want to bind simple content to a frontend component without having any specific backend/data composition logic but you envision a straight mapping between Sitecore Items and a cshtml view…

Code elements required within the asp.net core solution:

@model ContentBlockModel
<div>
@* Important: Self-closing tags will not work when rendering text fields with the Sitecore tag helpers. *@
<h1 class="contentTitle" asp-for="Title"></h1>
<div class="contentDescription">
<sc-text asp-for="Text"></sc-text>
</div>
</div>
view raw ContentBlock.cshtml hosted with ❤ by GitHub

here you can see two example of syntax asp-for and sc-text in action

using Sitecore.LayoutService.Client.Response.Model.Fields;
namespace MyProject.Models
{
/// <summary>
/// An example of binding to component fields (usually a serialized datasource item).
/// </summary>
public class ContentBlockModel
{
public TextField Title { get; set; }
public RichTextField Text { get; set; }
}
}
view raw ContentBlockModel.cs hosted with ❤ by GitHub

important elements within the startup.cs

Sitecore elements

data Template

Rendering creation using Json Rendering Template

rendering datasource configuration:

Content Item

Assigning the rendering to the Item

rendering datasource configuration

Layout Service

in case you need to trouble shoot having a look at the layout service is always a good idea http://sc10nsc.dev.local/sitecore/api/layout/render/jss?item=/&sc_apikey={xxxxxxxxxxxxxxxxxxxx}

if you were wondering how it looks like:

further reference to the Sitecore documentation and sample project:

https://github.com/Sitecore/Helix.Examples/tree/master/examples/helix-basic-aspnetcore

https://doc.sitecore.com/developers/100/developer-tools/en/sitecore-asp-net-rendering-sdk.html

Azure Best Practice – Backup your CD/CM WebApp

This is a very simple but very important tip that I would recommend almost in all Sitecore PAAS implementation that I have worked on…

Unfortunately Azure OOTB does not enable the backup of your Azure WebApp, that means that if you delete some files or break something within your deployments, there is not an easy way to get back in time and restore it the files that you have changed.

My recommendation is to enable the Backup functionality of CD & CM web apps so that you can always easily restore a copy back in time in case something goes wrong.

The Backup will cover the entire FileSytem of your webApp therefore all the original Sitecore solutions + all the config files + All the deployed assets

You can either backup on demand or backup on the schedule, the schedule option or take a backup before deployment is my recommendation

Azure Best Practice – Configure Application Initialization to reduce Cold Startup time

This tips is required in the case you have multiple instances of your web app and it will prevent Azure bringing into the load balancer the cold instances until the cold instances have been warmed up and ready to serve traffic effectively..

Application Initialization was introduced few years ago with IIS 8 https://docs.microsoft.com/en-us/iis/configuration/system.webserver/applicationinitialization/

but it is surprising to see that not all the website hosted on Azure use this useful feature…

<system.webServer>
<applicationInitialization
doAppInitAfterRestart="true"
skipManagedModules="true">
<add initializationPage="/" />
<add initializationPage="/page1/" />
<add initializationPage="/Category/page2/" />
</applicationInitialization>
</system.webServer>
view raw AppInit hosted with ❤ by GitHub

Sitecore Symposium 2020 Recap

Sitecore Symposium was very different in 2020 being forced to be an entirely online session… I am sure that the entire Sitecore audience got a different feedback on this format, some people saved several hours of travel time, but most of the people probably missed the unique vibe that only a LIV Symposium create within the Sitecore community…

Anyway coming to the announcements here the big news for Sitecore community:

Sitecore AI Autopersonalization

This feature was expected and it is good to see in Sitecore roadmap, obviously I feel it is fair to leverage the expectations since it will take some time to develop a mature AI auto personalization and there are other tools that claim the same goal but there is still margin for improvement. here you can read Sitecore announcement: https://www.sitecore.com/company/news-events/press-releases/2020/10/sitecore-makes-ai-powered-auto-personalization-a-standard

Sitecore as a Service

this was also expected, Sitecore aims to release content hub as a SAAS platform within the next 12-18 months. This is a further evolution of the current managed service offer and some customers will be certainly interested in this new delivery model

Next.js SDK for JSS to facilitate JAMStack and static site generation

This is a great news for all the developers who are considering building on the JAMStack using Sitecore facilitating Server Side Renedering and Static website generation without loosing all the benefits of Sitecore personalization

Sitecore 10.1 will be released early 2021 and has a brand new UI/UX in addition to Horizon

other new stuff coming in 2021

Azure Best Practice – Disable FCN for Sitecore Azure webApp

This trick is very important to avoid unexpected app pool recycling when deploying Sitecore on Azure Website especially on your CD

My understanding is that this issue could happen if you have not configured local storage. Note that local storage could bring some issues with media library and it is not recommended in all the scenarios.

However worth noting that once you disable the file system watcher you will need to do some manual restart of your webapp in case you change some configs / asp.net folder that otherwise would have forced a working role restart…

<system.web>
<httpRuntime fcnMode="Disabled" />
</system.web>
view raw web.config hosted with ❤ by GitHub

Sitecore 10 for developers

Sitecore 10 bring in loads of exciting new things for developers the more important in my opinion are:

  • asp.net core
  • Serialization CLI + VS Addon
  • Horizon UI
  • Containers

Due to my MS developer background, asp.net core is the more exciting news for me and confirm the maturity of Sitecore as an headless CMS

these two drawings explain high level asp.net core architecture

As you can see there is a clear decoupling in term of hosting from the custom code and the Sitecore instance that provide a set of services to a variety of web sites / apps etc..

When should you use asp.net core? I am leaving Sitecore to respond with one of their slides….

further info…

and

Sitecore CLI is the new serialization engine that is going to replace Unicorn and TDS, it comes with a CLI and a VS add-on I have tested it and I am looking forward to get it within my deployment pipeline…

further info:

Get To Know an MVP – Stelio Di Bello

Recently has been recorded a podcast where I talk with Tamas Varga about my Siteore journey, here you can find the link on CoreSampler website to listen the PodCast:

https://coresampler.fm/91

and here you can find a transcript of the conversation with Tamas:

Tamas:  Hi Stelio, please introduce yourself 

Stelio: My name is Stelio Di Bello, I am originally from south Italy and I moved to the UK thirteen years ago.

At the beginning of my career I have worked for Microsoft consulting services and I became a regional expert on Microsoft Commerce Server, the father of Sitecore Commerce…
Nowadays I work for my own company that’s an independent Sitecore consultancy, I work as technical architect and, I truly enjoy technology.
In my free time I am also an international Bridge player and I like to experiment with technology exploring conversational interfaces such as Amazon Alexa and face rekognition.
I work for big / enterprise clients within different industries and multimillion ecommerce websites. In my engagements, I do not work only with Sitecore but with with a variety of web technologies such as Akamai, Azure, AWS, FrontEnd development, Google Analytics, Tag Managers, Tracking & Optimisation products and everything else MarTech related…

Thanks to Sitecore, my work gravitates between IT & Marketing trying to deliver world class performing website in a very agile & flexible way of working to keep marketing department happy…
I have been awarded Sitecore MVP in the technology category for 6 years in a row.

Tamas: When did you join the Sitecore Community? 

Stelio: I have always been a big fan of Microsoft Content Management Server 2002 and I have actually, never felt in love with Sharepoint…
First time that I have heard about Sitecore was in 2009, when I was considering on a project to replace Sharepoint with Sitecore 6.2, in the end sadly we decided to keep Sharepoint… few years later following to that parenthesis I have done my first Sitecore 6.5 project and, after that  I have not been able to leave Sitecore world anymore… Within these years, I have been involved in several crazy and exciting projects… once a  Formula 1 client asked me to build a website from scratch in just three weeks from Wireframes to deployemnt, and I did it..  in the end, the website won a Sitecore experience award for marketing agility…
Within these years, I am always been a keen blogger and in my engagements, I do a lot of evangelism to other developers about Sitecore new versions / new functionalities and the best way to leverage the full Sitecore potential, such as personalization and testing capabilities.

Tamas: What do you find the most appealing in the Sitecore Community?

Stelio: When you are a developer and you are facing a problem and go on line searching for a solution and you find the exact answers to your problem on Stack exchange or on a blog post that is the moment that you realize that you have to give back…  share your experience so that other people can benefit from your learning and experience as you are learning from other people… I also quite enjoy attending Sitecore events in person, such as Sitecore user groups in London or SugCon Europe, meeting with other community members to share experiences and make friends keeps it fun and real

Tamas: What is your suggestion for someone would like to be an MVP? 

Stelio: I would recommend to everybody to follow their passion and share their experiences in any format that they find appropriate, it could be a blog, or a youtube video, a project on github or a module on marketplace…. every contribution is valuable to the community and everybody has to be able to express in the way that they feel more comfortable doing it…  the more important suggestion is to be passionate about technology and enjoy Sitecore…

Tamas: What is your favorite motivational quote?

Stelio: My favorite quote is:

simplicity is the ultimate sophistication” from Leonardo da vinci

I truly believe that often keeping it simple and effective is the key to success…

I often find situations where we are asked for perfect solutions that end up building unrequired complexity, often I see clients who wants to have way too many non production environments and end up spending loads of money on it…

don’t do it! keep it simple and effective and enjoy Sitecore!

Azure Best Practice – Compilation optimization for Sitecore Webapp on Azure

I have seen in few instances deployed on Azure PAAS an issue with recompilation leading to the app pool restart…

my recommendation for the <compilation> tag in the web.config is to add the following attribute numRecompilesBeforeAppRestart=”100″

this attribute will prevent restarting when it reaches 10 recompilations (note that 10 is the default value in case you do not specify it)

In case you have been investigating random restarts you should find in the Sitecore and Azure logs a message that explicit tell you that the application restarted since it reached the maximum number of recompilations

Note that if you are hosting your instance in Azure WebApp this is likely to be happening, since I have seen this issue in several instances…

<compilation defaultLanguage="c#" debug="false" targetFramework="4.6.2" numRecompilesBeforeAppRestart="100"/>

view raw
web.config
hosted with ❤ by GitHub

Azure Best Practice – Disable FileSystem watchers to improve Sitecore stability on Azure webApp

I have seen few Sitecore instances deployed on Azure having issues with the filesystem watcher forcing the instance to restart, however in my experience file system watchers are not very useful since code got change only within the deployments…

Best way to ensure if you are experiencing any issue is to check your Sitecore logs and find the reason for the restart of your webapp… if the reason for restart points you to the file system changes, I would suggest applying the following patch to stabilize your sitecore instance…

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"&gt;
<sitecore>
<settings>
<setting name="Media.FileSystemWatcher.BufferSize" value="16384" >
</setting>
</settings>
<watchers>
<patch:delete />
</watchers>
<mediaLibrary>
<watcher>
<ignoreList>
<patch:delete />
</ignoreList>
</watcher>
</mediaLibrary>
</sitecore>
</configuration>

view raw
DisableWatchers
hosted with ❤ by GitHub

How to coexist Sitecore SSO AD owin with another public-facing provider

I am not sure if I have been particularly “unlucky” or if that’s going to become a common issue for Sitecore administrators but I found myself in a particular scenario where on the public website AD-B2C was used to authenticate external users and at the same time they wanted to use AD to access to the Sitecore content authoring….

the exact scenario is the following:

http://www.myclient.com –> using ADB2C to authenticate website customers

cms.myclient.com –> using AD to authenticate content authors

investigating the issue, came lear to me that there was an issue with the AD Cookies between the .AspNet.Cookies cookie issued for the CD and the cookie issued for the CM…

note that within the AD provider you cannot really change  the name of .aspnet.cookies (or at least it is not trivial to do it…)

the simplest solution that I come up with was to clear this cookie on the Sitecore login page so that I can ensure that Sitecore CMS AD provider won’t be confused with the cookie issued from the CD server…

<script runat="server">
//This snippet goes into sitecore/login/default.aspx
protected override void OnPreInit(EventArgs e)
{
if (Request.Cookies[".AspNet.Cookies"] != null)
{
//Force expiration of SSO cookie on .yourclient.com domain
HttpCookie myCookie = new HttpCookie(".AspNet.Cookies");
myCookie.Expires = DateTime.Now.AddDays(1d);
myCookie.Domain = "yourclient.com"; // !!!!
Response.Cookies.Add(myCookie);
}
}
</script>

view raw
default.aspx
hosted with ❤ by GitHub