Function Description: When the user requests a page, if the page needs to log in and then take action, the user is directed to the login page, the login is successful, automatically jump back to the previous page .
//Login Page view Code
PublicActionResult Login (stringRepath) { stringReurl=""; if(!String.IsNullOrEmpty (Repath)) {Reurl=Repath; } Else { stringHosturl=""; Hosturl=Request.urlreferrer = = null? Request.Url.Host:Request.UrlReferrer.Host;
Hosturl = "http://" + Hosturl;
Pathurl = Request.urlreferrer = = null? "/": Request.UrlReferrer.PathAndQuery;
Reurl = Hosturl + Pathurl;
}
Viewdata[reurl] = Reurl;
return View ();
}
Post method for the login page
[post]
Public ActionResult Login (string userName, string pwd, String repath) { ....//The office determines whether the login is successful return Json (code =:, ur L = repath); }
Idea: When you go to the login page, record the return path Reurl in the controller, and then pass the Reurl to the hidden domain of the login page via ViewData, and then pass Reurl to the Post method login when the request is signed in. Determine the success of the login after the end of the Reurl and passed to the front end, the front-end jump success.
Return path Delivery direction: Login→login (View) →login (post) → Front end
ASP. NET MVC implementation returns to previous page action after login