• Stars
    star
    804
  • Rank 56,681 (Top 2 %)
  • Language
    C#
  • License
    MIT License
  • Created about 7 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Various ASP.NET Core middleware

Middleware

Various ASP.NET Core middleware. Mostly for use in APIs.

ProblemDetails NuGet

Install-Package Hellang.Middleware.ProblemDetails

Configure in Startup class. See examples:

Other packages that integrate with ProblemDetails middleware:

Logo

corrupted file by Rflor from the Noun Project

SpaFallback NuGet

Install-Package Hellang.Middleware.SpaFallback

The SpaFallback middleware is designed to make your client-side SPA routing work seamlessly with your server-side routing.

When a request for a client-side route hits the server, chances are there's no middleware that will handle it. This means it will reach the end of the pipeline, the response status code will be set to 404 and the response will bubble back up the pipeline and be returned to the client. This is probably not what you want to happen.

Whenever a request can't be handled on the server, you usually want to fall back to your SPA and delegate the routing to the client. This is what the SpaFallback middleware enables.

The middleware works by passing all requests through the pipeline and let other middleware try to handle it. When the response comes back, it will perform a series of checks (outlined below) and optionally re-execute the pipeline, using the configured fallback path. This defaults to /index.html. This should bootstrap your SPA and let the client-side routing take over.

The following rules are verified before a fallback occurs:

  1. The method is GET.
  2. The status code is 404.
  3. The response hasn't started yet.
  4. The requested path does not have a file extension.
  5. The request actually reached the end of the pipeline.

The middleware tries to be as smart as possible when determining whether a fallback should happen or not:

If the request path has a file extension, i.e. /public/image.png, the client probably wanted an actual file (typically served by StaticFiles), but it was missing from disk, so we let the 404 response through to the client.

In addition, we check that the response wasn't handled by other middleware (but still ended up with a 404 status code). This is useful if you want to prevent disclosing the existence of a resource that the client don't have access to. In order to achieve this, AddSpaFallback will automatically inject a "marker middleware" at the end of the pipeline. If the request reaches this middleware, it will set the response status code to 404 and add a tag to the HttpContext.Items dictionary. This tag is then checked in the fallback middleware to verify a "hard" 404.

Usage

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddSpaFallback();
        services.AddMvc();
    }

    public void Configure(IApplicationBuilder app)
    {
        app.UseSpaFallback();
        app.UseStaticFiles();
        app.UseMvc();
    }
}

Authentication.JwtBearer.Google NuGet

Install-Package Hellang.Authentication.JwtBearer.Google

Makes it straight-forward to hook up authentication with Google identity tokens, using Microsoft's existing Microsoft.AspNetCore.Authentication.JwtBearer for parsing and validating the tokens.

Usage

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddJwtBearer(x => x.UseGoogle(
        clientId: "<google-client-id>",
        hostedDomain: "<optional-g-suite-domain>"));

More Repositories

1

Scrutor

Assembly scanning and decoration extensions for Microsoft.Extensions.DependencyInjection
C#
3,214
star
2

scriptcs-editor

An ultra-lightweight editor with syntax highlighting and intellisense for scriptcs
C#
97
star
3

MimeTypes

A simple lookup from file name/extension to MIME/media type, generated from mime-db, which in turn is compiled from IANA, Apache and nginx's MIME types.
Puppet
70
star
4

EF.Interception

A library for intercepting EntityFramework actions, like insert, update and delete.
C#
41
star
5

EFCore.Sqlite.NodaTime

Adds support for NodaTime types when using SQLite with Entity Framework Core.
C#
32
star
6

Hellang.MessageBus

A MessageBus for .NET 3.5+, Silverlight 4+, Windows Phone 7+, Xamarin.iOS, Xamarin.Android and .NET for Windows Store apps (WinRT)
C#
17
star
7

LangVersionFixer

A tiny utility to set the LangVersion property of all *.csprojs in a folder
C#
16
star
8

github-contributions

A simple console program that lists out the merged PR count, grouped by repository, done by the specified author.
C#
7
star
9

KestrelPureOwin

A demo on running pure OWIN directly on top of Kestrel
C#
7
star
10

Redskap

A collection of blazing fast ๐ŸŽ๏ธ๐Ÿ’จ Norwegian ๐Ÿ‡ณ๐Ÿ‡ด utilities with a โœจ modern API โœจ
C#
6
star
11

NntpLib.Net

An RFC 3977 and RFC 4643 compliant NNTP client library for .NET, written in C#
C#
6
star
12

yEnc

A tiny library for yEncoding and decoding with .NET
C#
5
star
13

Nzb

A tiny library for parsing NZB documents with .NET
C#
5
star
14

ResourceHelperGenerator

An MSBuild task that generates a strongly typed helper class for resource files with support for string formatting.
C#
5
star
15

Serilog.ReSharper

ReSharper support for Serilog
C#
5
star
16

Conference

C#
4
star
17

ExpressionActivator

A fast object activator based on compiled expression trees.
C#
4
star
18

PlayingCards

A tiny library with primitive types for building card games, like Suit, Rank, Card and Deck.
C#
3
star
19

nancy-bootstrapper-prototype

C#
3
star
20

Caliburn.Micro.ExposedProperties

A small Caliburn.Micro extension to allow exposing Model properties through a ViewModel with a simple attribute.
C#
3
star
21

fag-miles

2
star
22

Nancy.Autofac.Dnx

An example of running Nancy on DNX451 with and Autofac bootstrapper.
C#
2
star
23

CommandHandlerExample

A simple example for decorated command handlers
C#
2
star
24

Glimpse.Autofac

A Glimpse plugin to show Autofac registrations and resolutions
C#
2
star
25

NzbStation

C#
1
star
26

NETMF-NNUG

Code from presentation at NNUG Stavanger, 24/8-11
C#
1
star
27

NancyAutofacAspNetCore

A minimal Nancy + Autofac + ASP.NET Core 3.0 sample application
C#
1
star
28

CommandLine

C#
1
star
29

CamelSnakeKebab

C#
1
star
30

JetBrains.Annotations.Dnx

C#
1
star
31

bluecone

Automatically exported from code.google.com/p/bluecone
C#
1
star
32

Boilerplate

My preferred ASP.NET Core setup, packaged up into a few method calls ๐Ÿ”ฅ
1
star
33

blazor.jwttest

Quick test using JWT authentication for a blazor hosted (Client/Serverside) app with API and Authentication.
C#
1
star