日期:2014-05-17  浏览次数:21025 次

懂MVC3的进!
想做这种效果!
当用户从新登陆 或者因为cookie过期了 从新登陆后需要回到原来的页面
    但目前的代码是  当登陆过程中有过错误(密码或者用户名错误再次点击登陆)  就返回不到原来的页面了 。
View:Logon.cshtml

@using (Html.BeginForm("LogOn", "Account", new { Request.ServerVariables["http_referer"] }, FormMethod.Post))
    {...

Controller中的Logon Action:

[HttpPost]
        public ActionResult Logon(LogonInfo model, string returnUrl)
        {
                string[] loginResult;
  
                if (!string.IsNullOrEmpty(model.UserID) && !string.IsNullOrEmpty(model.Password))
                {
                    // 验证登陆
                    if (this.TryLogin(model.UserID, model.Password, out loginResult))
                    {
                        //model.UserName = string.Empty;
                        //Response.Cookies.Remove(model.UserID);
                        Response.Cookies.Remove(model.UserID);
                        ...
                        //其他操作.....
                        // 记住登陆状态
                        FormsAuthentication.SetAuthCookie(model.UserID, model.RememberMe);
  
                        if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                        {
                            return Redirect(returnUrl);
                        }