Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have done login using session a little code snippet below
C#
if (dt.Rows.Count > 0)
                {
                    Session.Add("UserID", dt.Rows[0][0].ToString());
                    Session.Add("Username", dt.Rows[0][1].ToString());
                    Session.Add("UserEmail", dt.Rows[0][2].ToString());
                    Response.Redirect("~/Home.aspx", false);
                    
                }

login page working fine and after logged In it leads to me home.aspx but the problem is as i click back button of my browser it lead to me login page again.
Posted
Comments
Zoltán Zörgő 3-Jul-13 3:00am    
As I know, you can't stop this. But why should you?
Muhamad Faizan Khan 3-Jul-13 3:18am    
what ? isnt possible;-( i want to stop this becuase user already logged in
Zoltán Zörgő 3-Jul-13 3:43am    
Well, than act accordingly within the logic of your application. Although Rohan Leuva's suggesion could work, it won't prevent user to enter login url directly, or use it as bookmark. So you still have to deal with it in your application logic.

1 solution

Use the below code on the page head which you want to prevent to be landed using back button

XML
<script type="text/javascript">
  function preventBack() { window.history.forward(); }
  setTimeout("preventBack()", 0);
  window.onunload = function() { null };
</script>

<script language="JavaScript" type="text/javascript">
  javascript: window.history.forward(1);
</script>


And a lot more can be found here

logout button code...[^]

Regards..:laugh:
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900