Skip to content

Instantly share code, notes, and snippets.

@ganjeii
ganjeii / ColorConsole.cs
Created January 10, 2023 19:26
A .NET Color Console Helper
/// <summary>
/// Console Color Helper class that provides coloring to individual commands
/// ref: https://weblog.west-wind.com/posts/2020/Jul/10/A-NET-Console-Color-Helper
/// </summary>
public static class ColorConsole
{
/// <summary>
/// WriteLine with color
/// </summary>
/// <param name="text"></param>
@ganjeii
ganjeii / ExampleHttpStreamHelperImplementation.cs
Last active April 1, 2022 14:18
Use to stream http request/response. This is now the recommended way to make http requests. Prevents having to wait for content to arrive all at once before processing.
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
namespace MyWebApiProxy.Examples
{
@ganjeii
ganjeii / ClientIP.cs
Created June 26, 2021 17:54 — forked from winzig/ClientIP.cs
If you're using a load balancer that obscures the remote client's true IP address, you can run this IHttpModule to take the first IP address from the X-Forwarded-For header, and overwrite the REMOTE_ADDR and REMOTE_HOST server variables. (We tried to use the URL Rewrite module that everyone normally recommends to do this, but it's buggy.)
using System;
using System.Web;
using System.Text.RegularExpressions;
namespace HttpModules
{
/// <summary>
/// This module handles complications from our load balancer configuration not properly passing the client's true IP
/// address to our code via the REMOTE_ADDR and REMOTE_HOST variables. We tried to use URL Rewrite to compensate for
/// this, but it does not run when default documents are being accessed (a longstanding bug).