Skip to content

Instantly share code, notes, and snippets.

@x789
x789 / Mapping
Created October 13, 2022 06:53
ASP.NET Core + W3C TraceContext
// Mapping of .NET Activity Context to W3C TraceContext
var traceId = Activity.Current!.ParentId; // W3C 3.2.2.3 trace-id
var parentId = Activity.Current!.ParentSpanId; // W3C 3.2.2.4 parent-id
var spanId = Activity.Current!.SpanId; // This service's span-id. Will become parent-id of next call
@x789
x789 / InvalidModelStateResponseFactory.cs
Created March 9, 2023 16:21
ASP.NET Custom Response on Model-Validation Error
using System;
using Microsoft.AspNetCore.Mvc;
public class InvalidModelStateResponseFactory
{
public static ProblemDetails Create(ActionContext _) => new();
public class ProblemDetails : IActionResult
{
public Task ExecuteResultAsync(ActionContext context)