我的登录代码如下://
// POST: /Account/LogOn
// 提交登录信息
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
UserModel um = AccountMembershipService.ValidateUser(model.UserName, model.Password);
if (um != null)
{
AddCookie(um.UserID, um.Name, um.Roles, model.RememberMe);
Session["UserInfo"] = um;
if (um.Roles == "User")
{
// 如果为系统用户,同步登录到UCenter
ucClient.UC_User_Synlogin(um.UCenterID);
}
if (Url.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "您尝试的登录不成功!");
return View(model);
}
}
else
{
return View(model);
}
}当未经验证的用户登录时,URL为:/Account/LogOn?ReturnUrl=%2ffixcom%2fadmin,当时登录成功后不能返回ReturnUrl的路径,总是返回到主页(已成功登录)。
一下两种代码也都尝试过,问题依旧。//
// POST: /Account/LogOn
// 提交登录信息
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
UserModel um = AccountMembershipService.ValidateUser(model.UserName, model.Password);
if (um != null)
{
AddCookie(um.UserID, um.Name, um.Roles, model.RememberMe);
Session["UserInfo"] = um;
if (um.Roles == "User")
{
// 如果为系统用户,同步登录到UCenter
ucClient.UC_User_Synlogin(um.UCenterID);
}
if (!String.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "您尝试的登录不成功!");
return View(model);
}
}
else
{
return View(model);
}
}
//
// POST: /Account/LogOn
// 提交登录信息
[HttpPost]
public ActionResult LogOn(LogOnModel model)
{
string returnUrl = Request["ReturnUrl"];
if (ModelState.IsValid)
{
UserModel um = AccountMembershipService.ValidateUser(model.UserName, model.Password);
if (um != null)
{
AddCookie(um.UserID, um.Name, um.Roles, model.RememberMe);
Session["UserInfo"] = um;
if (um.Roles == "User")
{
// 如果为系统用户,同步登录到UCenter
ucClient.UC_User_Synlogin(um.UCenterID);
}
if (!String.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "您尝试的登录不成功!");
return View(model);
}
}
else
{
return View(model);
}
}
为您的表单加上RouteValues参数为读取LogOn的QueryString["ReturnUrl"]即可,如下:
<%using ( Html.BeginForm( "LogOn", "Account",new{ReturnUrl=Request.QueryString["ReturnUrl"]}, FormMethod.Post } ) )
回答正确,很好!
嗯,不错,顶
我也用同样的疑惑,望大牛们给予指点迷津