Skip to content

Instantly share code, notes, and snippets.

View halter73's full-sized avatar

Stephen Halter halter73

  • Microsoft
  • Kirkland, WA
View GitHub Profile
@halter73
halter73 / CookieOidcRefresher.cs
Last active November 9, 2023 17:29
ASP.NET Core OIDC Cookie Refresh
using System.Globalization;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.JsonWebTokens;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Microsoft.IdentityModel.Tokens;
@halter73
halter73 / MapGroup.md
Last active March 5, 2022 03:24
Route Grouping

Goals

  • Define a route pattern prefix in a single place
    • The prefix should support slugs, route constraints, etc...
  • Allow adding metadata to a specified collection (group) of endpoints using a single API call.
  • Any endpoint that can be added to an IEndpointRouteBuilder can also be added to a group.
    • MapGet, MapPost, etc...
    • MapControllers
    • MapHub<THub>/MapConnections/MapConnectionHandler
  • MapFallbackToFile
@halter73
halter73 / Program.cs
Last active September 18, 2019 22:24
using System;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
namespace SlowClose
{
class Program
{
public class ReconnectSample
{
private readonly HubConnection _hubConnection;
private Task _runTask;
private TaskCompletionSource<object> _startTcs;
private volatile bool _stopping;
public Task StartAsync()
{
_startTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
@halter73
halter73 / Program.cs
Last active March 29, 2019 06:26
Fill chunk
using System;
using System.Diagnostics;
using System.Runtime.Intrinsics.X86;
public class Program
{
public static void Main()
{
uint NumPrefixHexDigits(uint dataLength) => (35 - Lzcnt.LeadingZeroCount(dataLength)) / 4;
TpTrace Verbose: 0 : 26479, 1, 2018/07/25, 18:16:20.733, 3779983730968491, vstest.console.dll, TestPluginCache: Discovering the extensions using extension path.
TpTrace Information: 0 : 26479, 1, 2018/07/25, 18:16:20.742, 3779983737678626, vstest.console.dll, AssemblyResolver: Microsoft.TestPlatform.Extensions.BlameDataCollector: Resolving assembly.
TpTrace Information: 0 : 26479, 1, 2018/07/25, 18:16:20.743, 3779983739051533, vstest.console.dll, AssemblyResolver: Microsoft.TestPlatform.Extensions.BlameDataCollector: Resolved assembly.
TpTrace Information: 0 : 26479, 1, 2018/07/25, 18:16:20.748, 3779983743631456, vstest.console.dll, AssemblyResolver: Microsoft.TestPlatform.Extensions.EventLogCollector: Resolving assembly.
TpTrace Information: 0 : 26479, 1, 2018/07/25, 18:16:20.749, 3779983744683462, vstest.console.dll, AssemblyResolver: Microsoft.TestPlatform.Extensions.EventLogCollector: Resolved assembly.
TpTrace Information: 0 : 26479, 1, 2018/07/25, 18:16:20.750, 3779983746580772, vstest.console.dll, As
using System;
using System.Threading;
using System.Threading.Tasks;
namespace RunAsync
{
class Program
{
static void Main(string[] args)
{
@halter73
halter73 / BadRequestDiagnosticAdapter.cs
Last active November 21, 2017 03:11
Bad Request Diagnostic Connection Adapter
using System;
using System.Buffers;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal;
using Microsoft.Extensions.Logging;
namespace BadRequestDiagnosticAdapter
@halter73
halter73 / pipes.cs
Created July 13, 2017 07:57 — forked from davidfowl/pipes.cs
Pipe sample
using System;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines;
namespace WebApplication19
{
public class Program
{
public static async Task Main(string[] args)
[xUnit.net 01:00:01.3728665] Discovering: Microsoft.AspNetCore.TestHost.Tests
[xUnit.net 00:00:01.5530414] Discovered: Microsoft.AspNetCore.TestHost.Tests
[xUnit.net 00:00:01.5629820] Starting: Microsoft.AspNetCore.TestHost.Tests
[xUnit.net 00:00:04.0099135] Finished: Microsoft.AspNetCore.TestHost.Tests
[xUnit.net 00:00:01.9333799] Microsoft.AspNetCore.TestHost.TestClientTests.PostAsyncWorks [FAIL]
[xUnit.net 00:00:01.9627316] Microsoft.AspNetCore.TestHost.TestClientTests.PutAsyncWorks [FAIL]
[xUnit.net 00:00:02.0079628] Microsoft.AspNetCore.TestHost.TestClientTests.LargePayload_DisposesRequest_AfterResponseIsCompleted [FAIL]
[xUnit.net 00:00:02.0143873] Microsoft.AspNetCore.TestHost.ClientHandlerTests.ResubmitRequestWorks [FAIL]
Total tests: 51. Passed: 47. Failed: 4. Skipped: 0.