这是我的密码。请有人帮助我迫切需要上面提到的代码。
[HttpGet]
public ActionResult Index(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return View();
}
[HttpPost]
public ActionResult Index(LoginModel loginModel, string returnUrl)
{
if (ModelState.IsValid)
{
if (loginModel.Username == "user" && loginModel.Password == "password")
{
FormsAuthentication.SetAuthCookie(loginModel.Username, true);
return Redirect(returnUrl);
}
else
{
ModelState.AddModelError("", "The username or password provided is incorrect.");
}
}
ViewBag.ReturnUrl = returnUrl;
return View(loginModel);
}我正在跟踪以下链接:http://www.primaryobjects.com/CMS/Article155.aspx
发布于 2014-07-01 11:10:53
问题在哪里:
如果不使用returnUrl参数,然后将null传递给重定向()方法,那么会发生什么?--您得到的正是这个错误:)。
解决方案:
您可以检查url是否为空,或者使用microsft在默认mvc模板中包含的RedirectToLocal方法(或者编写自己的或..。etc只是不将null传递给重定向方法):
...
FormsAuthentication.SetAuthCookie(loginModel.Username, true);
// Here 'return Redirect(returnUrl);' become:
return RedirectToLocal(returnUrl);
...
private ActionResult RedirectToLocal(string returnUrl)
{
if (Url.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}https://stackoverflow.com/questions/24508548
复制相似问题