Skip to content

Instantly share code, notes, and snippets.

@davidfowl
davidfowl / dotnetlayout.md
Last active May 22, 2024 12:34
.NET project structure
$/
  artifacts/
  build/
  docs/
  lib/
  packages/
  samples/
  src/
 tests/
@davidfowl
davidfowl / PeekJsonToken.cs
Last active February 29, 2024 17:47
Peeking at a JSON token using a PipeReader in the ASP.NET Core request pipeline
using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO.Pipelines;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
@PizzaConsole
PizzaConsole / CustomResultFilterAttribute.cs
Created August 7, 2020 20:59
Use Custom Json Serialization Setting per Controller in ASP.NET Core 3.0+
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.Formatters;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Buffers;
namespace MyProject.Filters
{
@dazinator
dazinator / FormsAuthenticationTicketHelper.cs
Last active December 27, 2023 09:46
Decrypt a Legacy ASP.NET Forms Authentication Cookie (that uses SHA1 validation, and AES encryption) - without horrendous dependencies on system.web.. This allows you to decrypt a forms authentication cookie that was created in ASP.NET 3.5, from an ASP.NET 5 application.
internal static class FormsAuthenticationTicketHelper
{
private const byte CURRENT_TICKET_SERIALIZED_VERSION = 0x01;
private const int MAX_TICKET_LENGTH = 4096;
// Resurrects a FormsAuthenticationTicket from its serialized blob representation.
// The input blob must be unsigned and unencrypted. This function returns null if
// the serialized ticket format is invalid. The caller must also verify that the
// ticket is still valid, as this method doesn't check expiration.
@iamarcel
iamarcel / Creating Neat .NET Core Command Line Apps.md
Last active November 28, 2023 10:41
Creating Neat .NET Core Command Line Apps

Creating Neat .NET Core Command Line Apps

You can now read this on my (pretty) website! Check it out here.

Every reason to get more HackerPoints™ is a good one, so today we're going to write a neat command line app in .NET Core! The Common library has a really cool package Microsoft.Extensions.CommandlineUtils to help us parse command line arguments and structure our app, but sadly it's undocumented.

No more! In this guide, we'll explore the package and write a really neat

@xtream1101
xtream1101 / Backup&RestoreRepo.md
Created June 29, 2019 12:38
Backup and restore a git repo using git bundle

Backup/archive a repo

  1. Clone the repo
git clone --mirror https://github.com/vuejs/vue
  1. cd into the cloned repo
  2. Create a bundle file in the parent directory
git bundle create ../vuejs_vue.bundle --all
@ZacharyPatten
ZacharyPatten / readme.md
Last active February 3, 2023 15:58
GitHub Repository Checklist (C#)

GitHub Repository Checklist (C#)

Have a repository on GitHub? Planning on making a repository on GitHub? This checklist is intended to introduce you to various features that may help you make the most of your GitHub repository with specific recommendations for C# repositories.

Checklist

These are only suggestions.
They may not be appropriate for all repositories.
They are in no particular order.
Click each item to expand for more information.

@davidfowl
davidfowl / bedrock-server.cs
Last active December 8, 2022 15:18
A sample of the current API usage with bedrock's listener layer
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
@amanda-mitchell
amanda-mitchell / partial.Global.asax.cs
Last active September 12, 2022 11:48
Demonstrates how to decode an .ASPXAUTH cookie as generated by the current version of Microsoft's implementation of .NET. You should be able to drop this into the `Global.asax.cs` file of an ASP.NET project and be able to share cookies with code running on Mono. A few notes: (1) This assumes a machine key section that uses SHA1 validation and AE…
public void FormsAuthentication_OnAuthenticate(object sender, FormsAuthenticationEventArgs args)
{
var machineKeySection = (MachineKeySection) WebConfigurationManager.GetWebApplicationSection("system.web/machineKey");
var cookie = args.Context.Request.Cookies[".ASPXAUTH"];
if (cookie == null || !Regex.IsMatch(cookie.Value, "^([a-fA-F0-9]{2})+$"))
return;
var cookieBytes = ByteUtility.ToBytes(cookie.Value);
int signatureLength;
@kellishouts
kellishouts / gulp_sass_livereload.md
Last active January 24, 2022 06:40
Gulp + Sass + LiveReload 1.0

Gulp + Sass + LiveReload

This Gist goes over setting up a gulp workflow that will:

  1. watch for any sass changes, then compiles sass source into css
  2. watch for any changes in the public directory, and trigger live-reload
  3. serve static content in public/