Well unfortunately there is no fool proof way to prevent the user from going back. You can use JavaScript, but all the user has to do is to disable JavaScript and that trick is shot. You can use Sessions, but if the user doesnt accept cookies then that wont work. You can use the
HttpCachePolicy Class to prevent pages from caching, something like this (in the Page_Init Event)
csharp
Protected void Page_Init(object Sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
}
Most people use the JavaScript trick you have already posted, but then again if the user disables JavaScript that wont work either. Actually disabling the Back button isn't possible, think of the trouble programmers could get into if they could access a persons browser through a web application like that, a major security hole.
You could also try something like this:
csharp
Response.Buffer = True
Response.ExpiresAbsolute = System.DateTime.Now() - 1
Response.Expires = 0
Response.CacheControl = "no-cache"
//if the session variable has a length at all then the
//user has been here before so we need to wipe out
//the session and redirect them to the login page
if(Session["FirstTimeToPage"].ToString().Length > 0)
{
Session["FirstTimeToPage"] = string.Empty
Response.Redirect "/Login.aspx"
Response.End
}
//if we make it this far we can go ahead and load the page
This post has been edited by PsychoCoder: 3 Mar, 2008 - 06:53 PM