views:

78

answers:

2

Hi,

I'm using a LoginBox placed in MasterPage in order to user be able to login from any site pages.

The form action is declared by

<% using (Html.BeginForm("LogOn", "Account", FormMethod.Post))

but after POST and if failed login occurs i need stay on the same page and display Validation Messages.

So how can i do to stay on the calling page and not being redirected to Account LogOn View ?

Thanks.

A: 

You can append returnurl field in your login form:

using (Html.BeginForm("LogOn", "Account", FormMethod.Post, new { @returnurl=Request.Uri.AbsolutePath }))

and in your Account.LogOn action redirect back

ActionResult LogOn(Form form) { ... check login/password ... return Redirect(form["returnurl"])}
Tadas
A: 

So the post is going to your Account controller, LogOn action. I'd recommend you call a "Authenticate" action instead...

<% using (Html.BeginForm("Authenticate", "Account", FormMethod.Post))

That way, your action would do the authenticaion and a failed auth would return View() and a sucess would take you to LoggedIn view.

RailRhoad