想做这种效果!
当用户从新登陆 或者因为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);
}
else
{
return RedirectToAction("Index", "Home");
}
}
}
return View(model);
}想要 让它登陆过程中 出现错误不刷新页面 怎么做? if (ModelState.IsValid)貌似也刷新页面?
当用户从新登陆 或者因为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);
}
else
{
return RedirectToAction("Index", "Home");
}
}
}
return View(model);
}想要 让它登陆过程中 出现错误不刷新页面 怎么做? if (ModelState.IsValid)貌似也刷新页面?
可以看看上面链接的 JS(AppView.js)中的ajax部分。