You may have to show some code, but in your Startup.cs file have you set your cookie to define the ReturnUrlParameter?
services.ConfigureApplicationCookie(c =>
{
c.LoginPath = new PathString("/Account/SignIn"); // calls a controller and action
c.AccessDeniedPath = new PathString("/Account/PermissionDenied"); // calls a controller and action
c.ExpireTimeSpan = TimeSpan.FromDays(10);
c.SlidingExpiration = true;
c.Cookie.Name = AUTHENTICATION_COOKIE_NAME;
c.ReturnUrlParameter = "ReturnUrl"; // this line right here?
});
What about some error handling?
app.Use(async (context, next) =>
{
switch (context.Response.StatusCode)
{
case (int)HttpStatusCode.NotFound:
// page in the content tree
context.Request.Path = "/page-not-found";
break;
case (int)HttpStatusCode.Unauthorized:
// account controller
context.Request.Path = URLHelper.AddParameterToUrl("/Account/SignIn", "ReturnUrl", context.Request.Path);
break;
}
await next();
});
Notice how we add the return URL if the user is unauthorized (not logged in)?