locked
:( Disable browser back button, in Forms Authentication RRS feed

  • Question

  • User-590909136 posted

    Is there any possibility of disabling the back button after a user logs in. Iam using the forms with Forms Authentication. can anybody help me, its urgent!! for me..please!!

    Sunday, March 8, 2009 6:03 AM

Answers

  • User97111691 posted
    Johne, try doing like this. HttpContext.Current.Response.Write("<script language=JavaScript>top.location='" + System.Web.Security.FormsAuthentication.DefaultUrl + "'</script>"); HttpContext.Current.Response.End();
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 8, 2009 11:27 AM
  • User-1171043462 posted

    1. Add this to page load of login page and add the following condition  if the session variable is not empty set the user back

    protected void Page_Load(object sender, EventArgs e)

    {

    if (Session["Login"] != null)

    {

    Response.Redirect(
    "YourLandingPage");

    }

    Response.Cache.SetCacheability(HttpCacheability.NoCache);

    }

    2. After successful login set a session variable in the following way

    Session["Login"] = "success";

     

    3. when user presses back button page load of login page check the following if teh session variable is not empty set the user back

    if (Session["Login"] != null)

    {

    Response.Redirect(
    "YourLandingPage");

    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 8, 2009 11:48 AM
  • User1564875471 posted

    Johne, try doing like this. HttpContext.Current.Response.Write("top.location='" + System.Web.Security.FormsAuthentication.DefaultUrl + "'"); HttpContext.Current.Response.End();

    What is This ? how is it related to the problem ?

    1. Add this to page load of login page and add the following condition  if the session variable is not empty set the user back

    protected void Page_Load(object sender, EventArgs e)

    {

    if (Session["Login"] != null)

    {

    Response.Redirect(
    "YourLandingPage");

    }

    Response.Cache.SetCacheability(HttpCacheability.NoCache);

    }

    2. After successful login set a session variable in the following way

    Session["Login"] = "success";

     

    3. when user presses back button page load of login page check the following if teh session variable is not empty set the user back

    if (Session["Login"] != null)

    {

    Response.Redirect(
    "YourLandingPage");

    }

     

    No, There is no need to this at all. The OP was mentioned that he is using FormsAuthentication , and so there is no need to use the session here....

     

    Please , you just need to use the Code i mentioned in the my previous reply , let me know if  you are confused.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 8, 2009 11:55 AM

All replies

  • User-1171043462 posted

    Is there any possibility of disabling the back button after a user logs in. Iam using the forms with Forms Authentication. can anybody help me, its urgent!! for me..please!!

     

    You can do this way works in IE but FF will not execute nor give error

    http://mudassarkhan.wordpress.com/2009/01/10/disable-browser-back-button/

    Sunday, March 8, 2009 6:51 AM
  • User1623409651 posted

    Hi

    You have to use the java scrip for this like below

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

    best Regards

    Sunday, March 8, 2009 7:13 AM
  • User-1171043462 posted

    Hi

    You have to use the java scrip for this like below

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

    best Regards

    Rameez,

    As I said All these techniques dont work in Netscape browsers like FF and Chrome

    due to security reasons

    Sunday, March 8, 2009 7:32 AM
  • User1623409651 posted

    Rameez,

    As I said All these techniques dont work in Netscape browsers like FF and Chrome

    due to security reasons

    Thanks Muddasar Khan for correction and sugestion can u explain me why these browsers are not supported above java script statement.

    Best Regards

    Sunday, March 8, 2009 7:44 AM
  • User1564875471 posted

     It's a browser caching issue.What you need to do is to place the following code in the page_load of any page that you don't want it to be cached.

        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
        }

      Also , if you want to apply it to the whole pages , you can place that code in the MasterPage Page_Load handler or if you are not using a MasterPage, you can create a base class for your pages.

     

    Sunday, March 8, 2009 8:14 AM
  • User-1171043462 posted

    Thanks Muddasar Khan for correction and sugestion can u explain me why these browsers are not supported above java script statement.

    Best Regards

    FF treats it as unsecure if run it is called in events like body load which donot require user interaction

    It will not give any error but will  not work

    Sunday, March 8, 2009 9:20 AM
  • User-590909136 posted

    Thank youu for all the reply 

    but i want to do it through the code, i mean the C# codebehind. can anyone help me.

    Sunday, March 8, 2009 11:26 AM
  • User97111691 posted
    Johne, try doing like this. HttpContext.Current.Response.Write("<script language=JavaScript>top.location='" + System.Web.Security.FormsAuthentication.DefaultUrl + "'</script>"); HttpContext.Current.Response.End();
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 8, 2009 11:27 AM
  • User-1171043462 posted

    1. Add this to page load of login page and add the following condition  if the session variable is not empty set the user back

    protected void Page_Load(object sender, EventArgs e)

    {

    if (Session["Login"] != null)

    {

    Response.Redirect(
    "YourLandingPage");

    }

    Response.Cache.SetCacheability(HttpCacheability.NoCache);

    }

    2. After successful login set a session variable in the following way

    Session["Login"] = "success";

     

    3. when user presses back button page load of login page check the following if teh session variable is not empty set the user back

    if (Session["Login"] != null)

    {

    Response.Redirect(
    "YourLandingPage");

    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 8, 2009 11:48 AM
  • User-590909136 posted

    Thank you so much, binobose and mudassarkhan. it worked well. <br />
    Iam really grateful to this forum and you two for providing me with prompt answer.

    Sunday, March 8, 2009 11:54 AM
  • User1564875471 posted

    Johne, try doing like this. HttpContext.Current.Response.Write("top.location='" + System.Web.Security.FormsAuthentication.DefaultUrl + "'"); HttpContext.Current.Response.End();

    What is This ? how is it related to the problem ?

    1. Add this to page load of login page and add the following condition  if the session variable is not empty set the user back

    protected void Page_Load(object sender, EventArgs e)

    {

    if (Session["Login"] != null)

    {

    Response.Redirect(
    "YourLandingPage");

    }

    Response.Cache.SetCacheability(HttpCacheability.NoCache);

    }

    2. After successful login set a session variable in the following way

    Session["Login"] = "success";

     

    3. when user presses back button page load of login page check the following if teh session variable is not empty set the user back

    if (Session["Login"] != null)

    {

    Response.Redirect(
    "YourLandingPage");

    }

     

    No, There is no need to this at all. The OP was mentioned that he is using FormsAuthentication , and so there is no need to use the session here....

     

    Please , you just need to use the Code i mentioned in the my previous reply , let me know if  you are confused.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 8, 2009 11:55 AM
  • User1315639056 posted

     

    It's not working....i hv placed this in the page which i dont want to go back...but its not working...can u pls help me in any other way.....pls its urgent...
    Tuesday, March 17, 2009 3:09 AM
  • User1315639056 posted

     hey the below code is working in mozilla also...jst check once....u can place it in aspx page or master page of the related page.

    <script language="JavaScript">
                window.history.forward(0);
                function setFocus(theID){
                    document.getElementById(theID).focus();
                }
                function disableSubmitButton(formObj,id){
                formObj.submit();
                if(document.getElementById(id)!=null)
                document.getElementById(id).disabled=true;
                }
                </script>

     

     

    or simply use the below

    <script type="text/javascript" language="javascript">history.go(1)</script>

    Tuesday, March 17, 2009 3:36 AM