ASP. NET MVC implementation returns to previous page action after login

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.