ASP.NET Core Branch Previews: A Live URL per Pull Request
Your .NET pull request is approved on the strength of a diff and a green test run. Then it merges, deploys to staging, and the first person to open it finds that appsettings.Production.json was never updated for the new connection string. The tests passed because they never touched that file.
That gap is not a testing problem. It is a "nobody had a running copy of this branch" problem. An ASP.NET Core app is one of the easier stacks to give a live URL to, because the publish step produces a self-contained output directory and the app binds to whatever port you hand it. Three things have to be right: the published output, the bound port, and the environment name. Here is each one.
1. Publish, don't dotnet run
dotnet run is a development convenience. It builds into bin/Debug, watches for file changes, and picks up launchSettings.json — none of which you want in a preview environment. Publish instead:
dotnet publish -c Release -o ./out
The out directory is the whole application: your assemblies, the runtime config, and any content files marked CopyToOutputDirectory. If the app starts locally from dotnet run but fails in a preview, the usual cause is a content file that was never copied to the publish output. Check the .csproj:
<ItemGroup>
<Content Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
If your project references a .sln with multiple projects, publish the web project specifically — dotnet publish src/MyApp.Web -c Release -o ./out — otherwise you get a directory with no entry point.
2. Bind to the port you're given
ASP.NET Core reads the URL from ASPNETCORE_URLS, and Kestrel defaults to http://localhost:5000 when nothing sets it. A preview environment routes traffic to a container port, so localhost is the wrong interface and a hardcoded 5000 is the wrong port.
Set it in Program.cs so it works everywhere:
var builder = WebApplication.CreateBuilder(args);
var port = Environment.GetEnvironmentVariable("PORT") ?? "8080";
builder.WebHost.UseUrls($"http://0.0.0.0:{port}");
var app = builder.Build();
app.MapGet("/health", () => Results.Ok(new { status = "ok" }));
app.Run();
Two details matter here. 0.0.0.0 rather than localhost, because the router reaches the container from outside it. And a /health endpoint, because a preview that is up but unhealthy should be reported as failed rather than served as a blank page.
PreviewDrop sets PORT, HOST and HOSTNAME in the container. It does not inject a preview-URL variable, so don't build absolute links from one — read the request's Host header if you need them.
3. Name the environment
ASPNETCORE_ENVIRONMENT decides which appsettings.{Environment}.json loads and whether the developer exception page is on. A preview should run as Staging, not Development and not Production:
ASPNETCORE_ENVIRONMENT=Staging
Development turns on the exception page and disables the production error handler, which means your preview looks fine while the same code path fails in production. Production is worse in the other direction: it hides the stack trace you actually want when a preview breaks. Staging gives you production-like error handling with enough logging to diagnose a failure.
What PreviewDrop does and doesn't do for you
PreviewDrop detects the stack from the repository and generates the build plan — you don't need to commit a Dockerfile. For an ASP.NET Core project that means a publish step and a start command; if detection guesses wrong, you override the install, build and start commands in Project Settings.
Preview URLs look like prv-<id>.previews.previewdrop.dev. Each preview has a fixed lifetime set by your plan and is torn down when it expires — there is no idle-sleep-and-wake behaviour, so size the lifetime to how long a review actually takes.
Plan limits, from the pricing page:
| Plan | Concurrent previews | Preview lifetime | Memory per container |
|---|---|---|---|
| Free | 2 | 4 hours | 256 MB |
| Starter ($19) | 5 | 24 hours | 512 MB |
| Pro ($79) | 20 | 72 hours | 1 GB |
| Team ($149) | 40 | 168 hours | 2 GB |
Password-protected previews and custom preview domains are on Pro and above, not on Free or Starter. If you're previewing for a client rather than a teammate, that's the tier you need.
The three failures you'll actually hit
The app starts and immediately exits. Almost always a missing appsettings.json in the publish output, or a Program.cs that calls UseUrls with a port nothing is listening on. Check the container logs — the exit reason is in the first ten lines.
The preview loads but every request 500s. ASPNETCORE_ENVIRONMENT is unset, so the app fell back to Production and can't find its connection string. Set it explicitly.
Static files 404. UseStaticFiles() has to be called before UseRouting() in the middleware pipeline. It works locally because the dev server serves from the source tree; in a published output the wwwroot path is relative to the content root, which is the publish directory.
Getting the first preview
If you already have an ASP.NET Core repo, the fastest path is to connect it and open a pull request — the preview builds from the branch and comments the URL back on the PR. The quickstart walks through connecting a repository and reading the first build log, and signing up takes an email address and nothing else.
The point is not the URL. It is that the reviewer clicks the thing before it merges, and the appsettings mistake gets caught by a person instead of by a customer.
Want previews on your own pull requests? Start free — 2 concurrent previews, no credit card.