Quantcast
Channel: Brian Pedersen's Sitecore and .NET Blog
Browsing all 286 articles
Browse latest View live

Image may be NSFW.
Clik here to view.

C# .net Swagger API Versioning – Show versions in your Swagger page

So, Swagger does in fact support versioning in the interface. You just need to do it right, and remember to apply all the attributes and methods. An API with 2 versions, version 7 and version 8 First...

View Article


Image may be NSFW.
Clik here to view.

Serialization and deserialization of ‘System.IntPtr’ instances are not...

I added exception handling to my .net core 6 API, and any of my error messages just throws an error 500. The complete exception is as follows: System.NotSupportedException: Serialization and...

View Article


Image may be NSFW.
Clik here to view.

C# Azure Table Storage QueryAsync, Paging and Filtering

Azure Table Storage is a NoSQL key-value store that can store massive amounts of data in a semi-structured way. Data is stored using a PartitionKey/RowKey keyset and a list of values. So far so good,...

View Article

Run node.js on Windows server using NSSM

Node.js was probably never intended to be run on a windows server. It runs perfectly on Linux, and you can also run it without problems as an Azure App Service. But what if Node.js has to run on a...

View Article

Image may be NSFW.
Clik here to view.

Sitecore SOLR Search in multiselect lists fails unless you add the field to...

So I have this multiselect field in Sitecore: Sitecore Treelist Field The field is a treelist field, but this article works for all multiselect fields, treelist, checklist, multilist, etc. Treelist...

View Article


C# Authorization in .NET Core API’s using Attributes, TypeFilterAttribute and...

So the goal here is to define that a specific API endpoint in my .NET Core API requires an authorization token. It’s not all my endpoints that requires authentication, only those I specify. To obtain...

View Article

Image may be NSFW.
Clik here to view.

Could not load file or assembly ‘System.Diagnostics.DiagnosticSource,...

The following error may occur when upgrading Microsoft ApplicationInsights: [FileNotFoundException: Could not load file or assembly ‘System.Diagnostics.DiagnosticSource, Version=4.0.4.0,...

View Article

Sitecore TargetInvocationException: Exception has been thrown by the target...

You are probably upgrading some packages in your Sitecore instance, but instead of success and glory, you are greeted with the following error message: [TargetInvocationException: Exception has been...

View Article


Parameters and Arguments in .NET Core Command Line Applications

Microsoft have released a new System.CommandLine library to handle parameters and arguments in your .NET Core 6 console applications. The NuGet Package is currently (March 2nd 2023) in beta, so you...

View Article


Image may be NSFW.
Clik here to view.

C# Dapper Trim String Values

I was calling a stored procedure using Dapper, and for reasons beyond my understanding, the stored procedure returned strings as non-trimmed strings: Strings are not trimmed when returned from my...

View Article

C# byte size to string

How do you convert a byte size into a human readable string? There are many many ways of doing this. I made probably the simplest and most readable version, and wrapped it as an extension method:...

View Article

Sitecore The type or namespace name ‘Job’ does not exist in the namespace...

From Sitecore 9.0 to Sitecore 9.2, Sitecore updated the Jobs namespace: Job have become Sitecore.Abstractions.BaseJob abstract class and Sitecore.Jobs.DefaultJob concrete implementation. JobOptions...

View Article

C# String Token Replacer

Imagine this classic text where you need to replace tokens with some values: Welcome {{user}}. Click on this link to confirm your subscription: {{url}}. Tokens encapsulated in double brackets...

View Article


C# HttpClient and IHttpClientFactory in .net core

The C# HttpClient is the go-to library when you need to GET, PUT, POST or DELETE from an API Endpoint. But one of the issues with HttpClient is that it needs to be instantiated as a singleton. This is...

View Article

C# Use HttpClient to GET JSON from API endpoint

So, most API endpoints return JSON anyway, right? So why not make a method that can make a GET call to an API and return the response as an object directly? It’s actually not that hard: STEP 1: MAKE A...

View Article


Image may be NSFW.
Clik here to view.

.NET Core Caching in your API using AddResponseCaching and ResponseCache...

Caching the response of an API speeds up the API endpoint because the code that generates the response is not called, but rather fetched from memory. This is especially helpful for API’s where the...

View Article

C# Calculate Week Number from DateTime

Calculating the week number is harder than it should be. Not all countries calculate week numbers equally. First you need to know when a week starts. On a sunday? or on a monday? Then you need to know...

View Article


Image may be NSFW.
Clik here to view.

C# JWT Token Get Expiry Timestamp

In a previous post, I wrote on how to use JWT.Net to decode the JWT Token to get the expiry of the token. But there is a simpler way to do it. IdentityServer, among others, use this token to establish...

View Article

C# Convert XML to JSON using dynamic ExpandoObject, XDocument and...

So I receive these XML feeds from my client, but I need to enrich the contents before I can use the data. AND I would like to work with JSON instead. So how to do that with a few lines of code? Image...

View Article

Image may be NSFW.
Clik here to view.

Sitecore Scheduled Tasks Run only when you want them to

Sitecore Scheduled Tasks is one of the fundamental features of Sitecore that allows you to run background tasks based on a schedule. The most common scheduled task runner is the one that looks for...

View Article
Browsing all 286 articles
Browse latest View live


Latest Images