ASP.NET Core MVC Interview Question #197

How would you deploy an MVC application behind a reverse proxy?

Senior Practical MVC Scenarios & Production Architecture Senior Advanced

Quick Interview Answer

Configure the hosting environment so ASP.NET Core correctly understands forwarded scheme, host, and client information from trusted proxies. HTTPS termination, forwarded headers, Data Protection keys, authentication cookies, health checks, logging, and environment configuration must all match the deployment topology.

Detailed Explanation

Configure the hosting environment so ASP.NET Core correctly understands forwarded scheme, host, and client information from trusted proxies. HTTPS termination, forwarded headers, Data Protection keys, authentication cookies, health checks, logging, and environment configuration must all match the deployment topology.

Only trust forwarded headers from known proxies or networks. Incorrect proxy configuration can affect redirects, URL generation, authentication, and security decisions.

Code Example

var options = new ForwardedHeadersOptions
{
    ForwardedHeaders =
        ForwardedHeaders.XForwardedFor |
        ForwardedHeaders.XForwardedProto
};

app.UseForwardedHeaders(options);
app.UseHttpsRedirection();