Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am create a application. When user logout page is go to login page. but user is click to browser back button then go to previous visit page. so how to control user not see the previous page if it is not authorized user.
If possible please send the sample of project.
Posted

Have a look at this tip/trick: Browser back button issue after logout[^]
 
Share this answer
 
Use Forms Authentication.
Use some thing like this at web.config
XML
<location path="secure">
    <system.web>
      <authorization>
        <deny users="?"/>
        <deny users="jhon"/>
      </authorization>
    </system.web>
  </location>

secure is a folder which contains your secure webforms.
XML
<authentication mode="Forms">
      <forms loginUrl="Default.aspx"
           protection="All"
           timeout="30"
           name=".ASPXAUTH"
           path="/"
           requireSSL="false"
           slidingExpiration="true"
           defaultUrl="default.aspx"
           cookieless="UseDeviceProfile"
           enableCrossAppRedirects="false" >
        <credentials passwordFormat="Clear">
          <user name="kim" password="kim@123"/>
          <user name="jhon" password="jhonn"/>
        </credentials>
      </forms>
    </authentication>

Now at server side code

Default.aspx is your login form, Drag Two TextBoxes and a Button
at click event of button write following code. Default2.aspx is destination page. Secure is a folder which can have webforms which you wants to make secure
if (FormsAuthentication.Authenticate(TextBox1.Text, TextBox2.Text))
        {
            FormsAuthentication.SetAuthCookie(
                 this.TextBox1.Text.Trim(), false);

            FormsAuthenticationTicket ticket1 =
               new FormsAuthenticationTicket(
                    1,                                   // version
                    this.TextBox1.Text.Trim(),   // get username  from the form
                    DateTime.Now,                        // issue time is now
                    DateTime.Now.AddMinutes(10),         // expires in 10 minutes
                    false,      // cookie is not persistent
                    "HR"                              // role assignment is stored
                // in userData
                    );
            HttpCookie cookie1 = new HttpCookie(
              FormsAuthentication.FormsCookieName,
              FormsAuthentication.Encrypt(ticket1));
            Response.Cookies.Add(cookie1);

            // 4. Do the redirect. 
            String returnUrl1;
            // the login is successful
            if (Request.QueryString["ReturnUrl"] == null)
            {
                returnUrl1 = "Default2.aspx";
            }

            //login not unsuccessful 
            else
            {
                returnUrl1 = Request.QueryString["ReturnUrl"];
            }
            Response.Redirect(returnUrl1);

        }
 
Share this answer
 

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