登录.Net MVC后重定向到原始URL

时间:2015-07-09 02:27:33

标签: asp.net-mvc redirect login

我的登录代码:

 public ActionResult Login([Bind(Include = "Username, Password")] TaiKhoan tk)
        {
            var user = Request["user"];
            if (user != "")
            {
                string username = Request["user"];
                string pass = Request["pass"];
                var t = TaiKhoanBussiness.Login(username, pass, Session);
                if (t != null)
                {
                    FormsAuthentication.SetAuthCookie(username, true);
                    Session["taikhoan"] = t;
                    var s = FormsAuthentication.GetRedirectUrl(username, true);
                    Redirect(s);
                }
            }

在动作SachController / Comment中:

[HttpPost]
[Authorize]
public void Comment() {
   var strDGC = Request["dgc"];
}

评论时要求用户登录。登录后,我无法在登录之前检索最后一个URL以重定向。似乎FormsAuthentication.GetRedirectUrl(username, true)不起作用? 登录后如何重定向?页面受[Authorise]保护,因此我没有登录链接,包含RedirectURL

等内容

1 个答案:

答案 0 :(得分:0)

您可以将returnUrl传递给Action
public ActionResult Login([Bind(Include = "Username, Password")] TaiKhoan tk, string returnUrl)
{
.....
重定向(RETURNURL);
}