Alternatively, you can use cookies. I prefer this method because it leads to a cleaner address bar and looks more elegant. Also, the process is transparent to the user. This should also prevent some cybercriminals from using your login page to redirect to unwanted websites.
In the code where you are redirected to the login page:
Response.Cookies.Add(new HttpCookie("returnUrl", Request.Url.PathAndQuery)); Response.Redirect("login.aspx");
On the login page:
HttpCookie returnCookie = Request.Cookies["returnUrl"]; if((returnCookie == null) || string.IsNullOrEmpty(returnCookie.Value)) { Response.Redirect("Default.aspx"); } else { HttpCookie deleteCookie = new HttpCookie("returnUrl"); deleteCookie.Expires = DateTime.Now.AddDays(-1); Response.Cookies.Add(deleteCookie); Response.Redirect(returnCookie.Value); }
it
Note. If you encounter security problems, you should do some checking on the returned URL.
source share