[英]In ASP.net Identity, how do you redirect a user to a specific url after login?
I'm use the ASP.Net identity 2.0 package for my application. 我正在为我的应用程序使用ASP.Net Identity 2.0程序包。 After a user successfully logs in, I want to redirect them to a specific URL on the site.
用户成功登录后,我想将他们重定向到站点上的特定URL。 Presently, after successful authorization, it sends them back to the default index page.
当前,在成功授权之后,它将它们发送回默认索引页面。
I think it's somewhere in this section of AccountController.cs: 我认为它位于AccountController.cs的此部分中:
//
// POST: /Account/Login
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
// This doen't count login failures towards lockout only two factor authentication
// To enable password failures to trigger lockout, change to shouldLockout: true
var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout: false);
var user = await UserManager.FindByNameAsync(model.UserName);
switch (result)
{
case SignInStatus.Success:
if (user.LoginStage <= 0)
{
return RedirectToAction("EnableGoogleAuthenticator", "Manage");
}
else
{
return RedirectToLocal(returnUrl);
}
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl });
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Invalid login attempt.");
await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout: true);
return View(model);
}
}
Change RedirectToLocal(returnUrl);
更改
RedirectToLocal(returnUrl);
to return RedirectToAction("Action", "Controller");
return RedirectToAction("Action", "Controller");
But this means you are ignoring the returnUrl
. 但这意味着您将忽略
returnUrl
。
我使用Response.Redirect("~/SomePage", false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.