开发者

LoginBox in MasterPage With ASP.NET MVC

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 an开发者_如何学JAVAd display Validation Messages.

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

Thanks.


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.


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"])}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜