You can do with Cookies. I have create a sample with 3 pages
Home, About and Contact.
On About and Contact Pages I am creating a cookie and saving the page URL while in Home.aspx I am checking if Cookie exists then it will redirect to the page saved in Cookie.
Home
<h1>Home</h1>
<hr />
<a href="About.aspx">About</a><br />
<a href="Contact.aspx">Contact</a>
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
HttpCookie cookie = Request.Cookies["LastVisitedPage"];
if (cookie != null)
{
string url = cookie.Value;
Response.Redirect(url);
}
}
}
About
<form id="form1" runat="server">
<h1>About</h1>
<hr />
<a href="Contact.aspx">Contact</a>
</form>
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
HttpCookie cookie = Request.Cookies["LastVisitedPage"];
if (cookie == null || cookie.Value.IndexOf("About.aspx") == -1)
{
cookie = new HttpCookie("LastVisitedPage", Request.Url.AbsoluteUri);
cookie.Expires = DateTime.Now.AddDays(30);
Response.Cookies.Add(cookie);
Response.Redirect(Request.Url.AbsoluteUri);
}
}
}
Contact
<form id="form1" runat="server">
<h1>Contact</h1>
<hr />
<a href="About.aspx">About</a><br />
</form>
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
HttpCookie cookie = Request.Cookies["LastVisitedPage"];
if (cookie == null || cookie.Value.IndexOf("Contact.aspx") == -1)
{
cookie = new HttpCookie("LastVisitedPage", Request.Url.AbsoluteUri);
cookie.Expires = DateTime.Now.AddDays(30);
Response.Cookies.Add(cookie);
Response.Redirect(Request.Url.AbsoluteUri);
}
}
}