Why is my custom Episerver login redirecting to the homepage?

  • Page Owner: Not Set
  • Last Reviewed: 2019-06-10

I have a custom login form built for Episerver. I'm calling SignIn on a UISignInManager and then returning Redirect(url); from my controller. But my redirect is never followed, and the user is always redirected to the homepage. Why does that happen?


Answer

UISignInManager has logic within it that sets a redirect based of the returnUrl querystring parameter when a login attempt is successful. Unfortunately, that redirect will take precedence over your redirect. The solution is to go lower-level than Episerver and sign in with Entity Framework directly, using ApplicationSignInManager<T>:

var manager = HttpContext.Current.GetOwinContext().Get<ApplicationSignInManager<UserType>>();
bool success = manager.SignIn(username, password, returnUrl);