0

I have a Login page which serves the login functionality as well as a link to Register. On this page I get the previous page URL using

document.referrer

This helps to take the user back to the original page once login is successfull.

Now, there is a Register option on the same login page which takes to the Registration page. In a typical scenario when the user comes from some page, Page1, to the login page, Page2, and from there goes to Registration page, Page3, how do I keep track of Page1 so that on successfull registration the user is sent back to Page1 from Page3.

document.referrer

will return Page2 and will take back to the login page on successfull registration.

Any clues.

Codehelp
  • 4,157
  • 9
  • 59
  • 96

2 Answers2

0

You could url encode the relative path of page1 and pass it to page2 (login) though the query string. Eg. /login?redirectto=%2Fpage. If the user logs in then get the original page from the query string and redirect them. If the user navigates to the registration page then you could build the link so that it contains the same query string. Eg. @Url.Action("Register","Home", new {redirecto = Request.Params["redirectto"]}). You may have to urlencode the parameter again in the action link. Then once the user registers you should be able to do the same as before, pull the page1 url from the query string and redirect. Hope that all makes sense.

Andrew
  • 5,525
  • 5
  • 36
  • 40
0

The action of your login page should be like

public ActionResult login(string backAction, string backController){
    //Do your stuff
    return RedirectToAction(backAction, backController);
}

when you call your login you must pass via query string the argument of login like

@Url.Action("Login", "LoginController", new{ backAction = "action", backController = "controller" })
theLaw
  • 1,261
  • 2
  • 11
  • 23