在下面的代碼中,returnUrl傳遞給LogOn Action。 其中我應該聲明它,然後將它傳遞給LogOn Action?什麼是價值?如何聲明returnUrl並將值傳給
[HttpGet]
public ActionResult LogOn(string returnUrl)
{
if (User.Identity.IsAuthenticated) //remember me
{
if (shouldRedirect(returnUrl))
{
return Redirect(returnUrl);
}
return Redirect(FormsAuthentication.DefaultUrl);
}
return View(); // show the login page
並且在下面的第10行中的「Url」未定義。
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (Membership.ValidateUser(model.UserName, model.Password))
{
MigrateShoppingCart(model.UserName);
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
if (**Url**.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
我的頁面上進行重定向的方法(訪問一個頁面)你的問題有點困惑。你問如何將一個returnUrl傳遞給LogOn操作?如果是這樣,您是否詢問GET或POST的操作? – asymptoticFault
兩者。我不知道我應該在哪裏使用它。並且我應該在其中填充它 – niknaz