关于指定页跳转到登陆,登陆后再跳到指定页的方法
1.判断是否登陆,如果没有登陆则跳转到登陆页
public ActionResult Index() { if (!SignHelp.IsSign()) return ChangeResult(); return View(); } //跳到login页 public ActionResult ChangeResult() { var returnurl = HttpUtility.UrlEncode("/visitPage/index"); return Redirect("/login/index?returnUrl=" + returnurl); }
2.在登陆页取到地址,存放隐藏域
public ActionResult Index() { string returnurl = Request.QueryString["returnUrl"]; returnurl = HttpUtility.UrlDecode(returnurl); ViewBag.ReturnUrl = returnurl; return View(); }
3隐藏域
<input type="hidden" id="returnurl" value="@ViewBag.ReturnUrl" />
4.在js中进行处理
var returnurl = $("#returnurl").val(); location.replace(returnurl == "" ? "/home/index" : returnurl);