【发布时间】:2015-11-04 04:47:38
【问题描述】:
我正在尝试在我的登录操作结果中创建不同的重定向,因为如果用户登录并处于角色中,则重定向到特定视图
例如如果接待员登录重定向到`RedirectToAction("Index", "Booking");
我尝试了一个逻辑,但它不起作用...以下是我所做的。
private ActionResult RedirectToLocal(string returnUrl)
{
if (User.IsInRole("Doctor"))
{
if (Url.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Patient");
}
}
if (User.IsInRole("Receptionist"))
{
if (Url.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("PatientBooking", "BooKing");
}
}
if (Url.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("GeneralSearch", "Search");
}
}
编辑 下面是我在 Login ActionResult 中调用方法的方式
public async Task<ActionResult> Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid)
{
var loginbusiness = new LoginBusiness();
var result = await loginbusiness.LogUserIn(model, AuthenticationManager);
if (result)
{
return RedirectToLocal(returnUrl);
}
else
{
ModelState.AddModelError("", "Invalid username or password.");
}
}
return View(model);
}
但这对我没有任何想法???
【问题讨论】:
-
你有什么错误吗?
-
它不经过验证过程,它只是重定向到返回 RedirectToAction("GeneralSearch", "Search");方法@ElenaDBA
-
我认为问题在于你的条件逻辑
标签: model-view-controller asp.net-mvc-validation redirecttoaction