GithubHelp home page GithubHelp logo

wazzamatazz / aspnetcore.localhostrun Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 678 KB

Localhost.run integration for ASP.NET Core applications

License: MIT License

C# 96.64% PowerShell 1.99% Shell 1.37%
asp-net-core localhostrun

aspnetcore.localhostrun's Introduction

Jaahas.AspNetCore.LocalhostRun

A library for simplifying integration between ASP.NET Core applications and localhost.run.

Getting Started

Add the Jaahas.AspNetCore.LocalhostRun NuGet package to your application.

Add the localhost.run configuration to your application services:

services.AddLocalhostRunIntegration();

Add the forwarded headers and HTTPS redirection middlewares to your application pipeline:

if (env.IsDevelopment()) {
    app.UseDeveloperExceptionPage();
    app.UseForwardedHeaders();
}
else {
    app.UseExceptionHandler("/Home/Error");
    app.UseForwardedHeaders();
    app.UseHsts();
}

app.UseHttpsRedirection();

// Remaining configuration removed

Example

An example ASP.NET Core application can be found here.

Details

localhost.run is an excellent service for creating internet-facing tunnels to web applications running on localhost, acting as a reverse proxy that can serve your application over HTTP/80 and HTTPS/443. However, due to the way that localhost.run adds the X-Forwarded-* headers to proxied requests, ASP.NET Core's forwarded headers middleware requires some additional configuration to make it work with localhost.run.

The AddLocalhostRunIntegration extension method used in the example above performs the following actions:

  • Configures the ForwardedHeadersOptions for the application to use proxy headers named X_Forwarded_For, X_Forwarded_Host and X_Forwarded_Proto (instead of the standard X-Forwarded-For, X-Forwarded-Host and X-Forwarded-Proto names).
  • Configures ForwardedHeadersOptions so that ASP.NET Core will only process the X_Forwarded_For and X_Forwarded_Proto headers by default.
  • Clears the KnownNetworks and KnownProxies lists on the ForwardedHeadersOptions as per here to remove the default restrictions that only allow loopback proxies.
  • Configures the application's HTTPS redirection policy to redirect non-HTTPS requests to port 443 via an HTTP 307/Temporary Redirect response.

Automatic Forwarded Headers Configuration

When your application is started with the ForwardedHeaders:Enabled setting set to true (e.g. via the ASPNETCORE_FORWARDEDHEADERS_ENABLED environment variable) and you use WebHost.CreateDefaultBuilder or Host.CreateDefaultBuilder to create your web host builder, it is not necessary to add the forwarded headers middleware to your application pipeline; ASP.NET Core will add it automatically.

However, the HTTPS redirection middleware must always be manually added to the application if you require it.

Building the Solution

The repository uses Cake for cross-platform build automation. The build script allows for metadata such as a build counter to be specified when called by a continuous integration system such as TeamCity.

A build can be run from the command line using the build.ps1 PowerShell script or the build.sh Bash script. For documentation about the available build script parameters, see build.cake.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.