Skip to content

Instantly share code, notes, and snippets.

@vanillajonathan
Last active October 10, 2017 09:46
Show Gist options
  • Save vanillajonathan/faf0d87f1f22d85227d1940c2d7122df to your computer and use it in GitHub Desktop.
Save vanillajonathan/faf0d87f1f22d85227d1940c2d7122df to your computer and use it in GitHub Desktop.
ASP.NET Core middleware that forbids HTTP requests
app.Use(async (context, next) =>
{
if (!context.Request.Scheme.IsHttps) {
context.Response.StatusCode = StatusCodes.Status403Forbidden;
await context.Response.WriteAsync("HTTPS is required.");
return;
}
await next.Invoke();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment