I'm not a .NET developer but gotta provide a sample ASP.NET Core Web App (Model-View-Controller) to a client. But I have a problem when deploying it onto Kubernetes.
For example, when I click Privacy button, I get 404 errors.

//ex.
// root
www.example.com/custom/path
// Desired
www.example.com/custom/path/Home/Privacy
// Actual - 404 error as ingress cannot route it.
www.example.com/Home/Privacy
Code
I'm using nginx-ingress for routing traffics.
The ingress looks like (using rewrite)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
//...
// I have to use rewrite
nginx.ingress.kubernetes.io/rewrite-target: /$1
//...
spec:
ingressClassName: nginx
rules:
- host: www.example.com
http:
paths:
- backend:
service:
name: dotnet-service
port:
number: 8080
path: /custom/path/?(.*)
pathType: ImplementationSpecific
Program.cs
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
Views/Shared/_Layout.cshtml
<!DOCTYPE html>
<html lang="en">
<head>
@* Add below line for setting prefix for href in link tag *@
<base href="/custom/path/">
@* ... *@
<link rel="stylesheet" href="lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="MVPPractice.styles.css" asp-append-version="true" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">MVPPractice</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
@* ... *@
<script src="lib/jquery/dist/jquery.min.js"></script>
<script src="lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
Traffic flow
ASP.NET program's base is root(/) not /custom/path, that's why I use nginx-ingress's rewrite.

Current Issue
- Request
www.example.com/custom/path/
- Response 200
- href of
<a>is/Home/Privacywhich leads towww.example.com/Home/Privacy, it is supposed to be/custom/path/Home/Privacyso that it leads towww.example.com/custom/path/Home/Privacy.
- Click the link
<a>
- Requests
www.example.com/Home/Privacy - Response 404 (because
nginx-ingresscannot route it)
How do I set prefix for static file responses?
program.csfile? You should have a line something likeapp.UseStaticFiles();in there - do you?Program.csand_Layout.cshtml. I've got that line as I barely changed the code.X-Forwarded-Prefixand you configure the server to trust it, then everything should work without hard-coding anything.nginx-ingressfailed the route the request, it couldn't even reachasp.netprogram. The requested url need be based on root from dotnet's perspective.