Search code examples
asp.net-corereverse-proxy

Redirect() to root page not including base path


My app is configured in startup to have a base path since the app is being reverse proxied.

app.UsePathBase("/myapp");
public IActionResult OnGet()
{
    return Redirect("/en/");
}

However, when I visit the page, I get redirected to /en/ instead of /myapp/en/

How do I redirect while including the base path?


Solution

  • This can be accomplished by preceeding the path with a tilde in the Redirect call.

    public IActionResult OnGet()
    {
        return Redirect("~/en/");
    }