Sitecore ASP.NET Core SDK made open-source

A couple of weeks ago, Sitecore made the .NET Core variant of their Headless Rendering SDK open-source on GitHub. If you haven’t seen it yet, check it out here: https://github.com/Sitecore/ASP.NET-Core-SDK

With the release (or the planning of) this open-source SDK, the old Headless Rendering SDKs have not been updated past version 21.x, while JSS has received recent updates specifically for Sitecore 10.4.
This will most likely mean that, at some point, everyone will have to switch to the new SDKs when breaking changes occur in future Sitecore releases.

The open-source version of this SDK does come with some improvements compared to the old version, which I will highlight in the rest of this article.

Multisite support

The new version finally brings multisite support. This is done through a Middleware module which checks:

  1. Whether the ?sc_site query string is present in the request.
  2. And if not, it will determine the site name based on the request hostname, by mapping it against the Site collection data returned by the GraphQL SiteInfoCollectionQuery query.

The MultisiteMiddleware is part of the Sitecore.AspNetCore.SDK.RenderingEngine NuGet package. To enable this feature you need to 1) make sure the GraphQlClient is registered in DI, 2) add the necessary Multisite services to DI and 3) insert the Middleware in the application.

//Below snippets need to be added to the Program.cs

...
  
// Add the GraphQlClient to Dependency Injection
builder.Services.AddGraphQlClient(configuration =>
{
    configuration.ContextId = sitecoreSettings.EdgeContextId;
});

// Add the Multisite services to Dependency Injection
builder.Services.AddMultisite();

...
  
// Insert the MultisiteMiddleware into the application
app.UseMultisite();

...

Sitemap

A new package with the name SearchOptimization was introduced to deliver some out-of-the-box SEO features. Part of this new package is a sitemap feature which can either use the Experience Edge generated sitemap or use a proxy variant which directly forwards any sitemap requests to a different URL.

To enable this feature you need to 1) make sure the GraphQlClient is registered in DI, 2) add either the Edge or the Proxy sitemap services to DI and 3) insert the related Middleware in the application.

//Below snippets need to be added to the Program.cs

...
  
// Add the GraphQlClient to Dependency Injection
builder.Services.AddGraphQlClient(configuration =>
{
    configuration.ContextId = sitecoreSettings.EdgeContextId;
});

// Add the Edge version of the Sitemap service to Dependency Injection
builder.Services.AddEdgeSitemap();
// OR, use the proxy variant which will forward the request to a different URL
builder.Services.AddSitemap(c => c.Url = new("http://cd"));

...
  
// Insert the Sitemap Middleware into the application
app.UseSitemap();

...

Redirects

A second feature in the SearchOptimization package are Sitecore/SXA managed redirects. This feature uses the SiteInfoQuery GraphQL query to retrieve redirects for the context site as configured in Sitecore.

To enable this feature you need to 1) make sure the GraphQlClient is registered in DI, 2) add the necessary Redirects services to DI and 3) insert the Middleware in the application.

//Below snippets need to be added to the Program.cs

...
  
// Add the GraphQlClient to Dependency Injection
builder.Services.AddGraphQlClient(configuration =>
{
    configuration.ContextId = sitecoreSettings.EdgeContextId;
});

// Add the Redirects service to Dependency Injection
builder.Services.AddSitecoreRedirects();

...
  
// Insert the Redirects Middleware into the application
app.UseSitecoreRedirects();

...

Conclusion

All in all this new version of the .NET SDK already brings some highly anticipated features which lacked in the old version.
It is also exciting to see that it has now become open-source, allowing the entire community to contribute to the SDKs and deliver new, customer focussed, features in a much faster pace.

Before starting to use this new SDK in your website build, do note that it is still in a preview state and, at time of writing, only a v0.11 has been published. This means that there may still be some bugs in the new as well as the refactored functionalities of the SDK.