0

我对这段代码有问题:

public ActionResult Index()
{
    if (User.Identity.IsAuthenticated)
    {
          return RedirectToAction("Index", "User", new { Id = WebSecurity.GetUserId(User.Identity.Name) });
    }

     return View();
}

[HttpPost]
public ActionResult Login(LoginModel user)
{
     if (ModelState.IsValid && WebSecurity.Login(user.UserName.Trim(), user.Password.Trim(), true))
     {
         Session["UserName"] = user.UserName;

         return Redirect(FormsAuthentication.LoginUrl);
     }

     return Json(new { errorMessage = "Lietotāja vārds vai parole nav pareiza" });
}

用户控制器:

public ActionResult Index(int Id)
{
    return View();
} 

网络配置:

<authentication mode="Forms">
   <forms loginUrl="/Home/Index" timeout="2880" />
</authentication>

在 Websecurity.login 之后,我需要重定向到User/Index/id。当我在网络上查看时,我可以看到这个请求,但是页面视图是旧的。当我按 F5 或转到Home/Index时,我立即被重定向到User/Index/id

我可以在 Javascript 中做到这一点。登录后我得到了 success = true 并且可以使用更新页面

window.location.refresh()

但我想要一个更好的选择。

4

0 回答 0