I am running my Kestrel servers behind an IIS Reverse Proxy (.NET Core 1.0.0). It works great, except, certain cases - such as being redirected to a login page upon failed access - results in the user being sent to http://localhost:8080/Account/Login
(the address that Kestrel is bound to) instead of http://www.example.net/Account/Login
(the reverse proxy address).
I know that I can configure IdentityOptions in Startup.cs
, which also includes the ability to set LoginPath, like:
services.Configure<IdentityOptions>(options =>
{
options.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromDays(1);
options.Cookies.ApplicationCookie.SlidingExpiration = true;
options.Cookies.ApplicationCookie.LoginPath = PathString("/Admin/Login");
});
Unfortunately, I cannot set an absolute path.
I also looked into the possibility to inspect and rewrite the URL per this response, but I feel like this may not be the right way to go, though I don't have any direct reason as to why.
app.Use(async (context, next) =>
{
var baseUri = Configuration["Site:BaseUri"];
if (baseUri.Contains(context.Request.Host.ToString()))
{
await next();
}
else
{
var newUri = $"{context.Request.Scheme}://{baseUri}{context.Request.Path}{context.Request.QueryString}";
context.Response.Redirect(newUri);
}
});
On top of all of this, I did find this link from the FunnelWeb project which basically looks like what I am wanting to do (although, for an older version of ASP.NET).
I would appreciate any guidance to point me in the right direction.