0

我试图让我的网站在成功登录时运行重定向。我将所有会员路线都保留在一个区域中。

/membership/login/index
/membership/profile/index

我已经尝试了以下两种方法来尝试让它工作 - 登录成功,但重定向除了更改地址之外什么也没做。我尝试了以下方法,但结果都一样

[HttpPost]
public ActionResult Index(Login loginViewModel)
{
    ...
    return RedirectToRoute(new { Area = "Membership", 
               Controller = "Profile", Action="Index" });
}

导致这个

http://mysite.com/Membership/Login?ReturnUrl=%2fmembership%2fProfile

然后我的下一个努力

return RedirectToAction("Index", "Profile", new { Area = "Membership" });
....
http://mysite.com/Membership/Login?ReturnUrl=%2fmembership%2fProfile

最后

return RedirectToAction("Index", "Profile");
... 
http://mysite.com/Membership/Login?ReturnUrl=%2fmembership%2fProfile
4

2 回答 2

1

您当然可以重定向 HTTP 帖子(您不能做的是重定向它,然后期望重定向的响应也是 POST)。这里发生的情况是您成功地将请求重定向到正确的页面,但是有问题的页面需要身份验证,并且由于用户未通过身份验证,因此请求再次发送回登录页面。您应该在设置 cookie进行重定向(或执行您正在执行的任何身份验证机制)。

于 2013-09-09T21:41:14.520 回答
1

您必须在重定向之前保存 cookie。

FormsAuthentication.SetAuthCookie("UserName or somthing",false/true);
return RedirectToAction("Index", "Profile", new { Area = "Membership" });

现在它会工作..

于 2013-11-29T09:51:04.873 回答