Category Archives: c#

.NET Core MVC Web API – control DateTime format in JSON output using JsonSerializerOptions

When creating API’s with .NET Core MVC, you can control the JSON output by adding JsonOptions to the controllers: This will ensure that when requesting application/json from a GET method, the format returned is JSON. You can then add Converters … Continue reading

Posted in .net, .NET Core, c# | Tagged , , , , | 1 Comment

Sitecore Publish Items using the PublishManager

Sitecore have two entries to publishing: Create a new Publisher and call Publish() or PublishAsync() Use the Sitecore.Publishing.PublishManager You should use the PublishManager. Sitecore introduced the Publishing Service which is an optional external publisher that is much faster than the … Continue reading

Posted in .net, c#, General .NET, Sitecore 8, Sitecore 9 | Tagged , , | 2 Comments

Sitecore publish certain items on save

My Sitecore solution have some items, where changes to certain fields are so critical that they need to be published immediately. So when my user presses the Save button, I will open a popup dialog, asking if I should publish … Continue reading

Posted in .net, c#, Sitecore 6, Sitecore 7, Sitecore 8, Sitecore 9 | Tagged , , | 1 Comment

C# HttpClient POST or PUT Json with content type application/json

The HttpClient is a nifty tool for getting and sending data to a URL, but it works differently from the old fashioned WebRequest class. The content type is added to the post data instead of added as a header parameter. … Continue reading

Posted in .net, .NET Core, c#, General .NET | Tagged , , , | Leave a comment

C# Newtonsoft serialize property that is an array and a string

IdentityServer4 has a strange way of returning roles. If there is only one role, the property is a string: But if there is more than one role, the property is an array of strings: If the property is a string, … Continue reading

Posted in .net, .NET Core, c#, General .NET | Tagged , , | Leave a comment

Which of my old Sitecore posts are still valid in Sitecore 9?

I have been writing Sitecore blog posts since April 2006. The first ones were for Sitecore 4.2. Now, 13 years later, some of the old posts are still valid, while others are obsolete as the Sitecore API have changed. But … Continue reading

Posted in .net, .NET Core, c#, General .NET, Sitecore, Sitecore 4, Sitecore 5, Sitecore 6, Sitecore 7, Sitecore 8, Sitecore 9 | Tagged | Leave a comment

IdentityServer use IdentityModel to get user token and user info

Using IdentityServer have been made easier with the IdentityModel helper library. The library implements extension methods that maps the input and output to classes. GET ACCESS TOKEN: Use the PasswordTokenRequest and RequestPasswordTokenAsync to get the access token. replace your_domain, your_clientid … Continue reading

Posted in .net, .NET Core, c#, General .NET, Sitecore 6, Sitecore 7, Sitecore 8, Sitecore 9 | Tagged , , , , | Leave a comment

Sitecore use Application Insights Metrics and Telemetry

Although Sitecore have an integration for Application Insights (which is part of Azure Monitor), you can implement the TelemetryClient yourself. This is useful if you wish to log Metrics or Trace your own code, without involving the complete Sitecore solution. … Continue reading

Posted in .net, c#, Microsoft Azure, Sitecore 7, Sitecore 8, Sitecore 9 | Tagged , , | Leave a comment

Change date format using .NET Regular Expressions

You can use Regex.Replace to change the format of a date string. For example if your input string is YYYY/MM/DD but you need to change it to YYYY-MM-DD, you can use this small method: Regular expressions are unreadable as usual, … Continue reading

Posted in .net, .NET Core, c#, General .NET | Tagged , , | 1 Comment

Sitecore Item Clones is only a thing in the master database

The Sitecore item cloning is a technique in which you can create a copy of an item that inherits the field values of the original items. In the latest versions of Sitecore (at least from 9.0 and forward) you can … Continue reading

Posted in c#, Sitecore 8, Sitecore 9 | Tagged , , | Leave a comment