Displaying login errors on the same page that the request originated from

Topics: Core, Troubleshooting
Oct 25, 2012 at 10:38 AM

We have a login widget which is displayed in the header of every page. When the user successfully logs in, they are redirected to the original page that they logged in from by passing a returnURL in a hidden field and the logon controller then performs a RedirectLocal to the returnURL.

The issue we have is when the user fails to authenticate; we would like to keep the user on the original page that they attempted to log in from, and display a log in failed message next to the login widget in the header. If we use RedirectLocal to keep the user on the original page, then we lose all the ViewData values. If we return a new login shape, then we are able to display the login errors, but the user has been removed from the original page that they tried to log in from.

Is there any way to return the original shape that the request originated from in the controller? Or, if we store a List<string> of login errors in the session (TempData is not accessible in the driver), is it possible to add model errors in the driver for the widget?

Oct 31, 2012 at 9:45 PM

TempData is the way to go, since you are redirecting to the previous page. One way to get to the TempData property is by casting the IUpdateModel argument to a Controller.