Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I use login control and logout control from tool control.when
user login and working in site then it automatically logout.

my login code
C#
SqlParameter[] paramater = new SqlParameter[]
              {                              
                  new SqlParameter("@User_Name",Login1.UserName),
                  new SqlParameter("@Password",Login1.Password)                               
              };
            SqlDataReader dr = (SqlDataReader)db.ExecuteReader("Login", paramater);
            if (dr.HasRows)
            {
             FormsAuthentication.RedirectFromLoginPage(Login1.UserName, false);
             Response.Redirect(@"~/Home.aspx", false);
            }

In web config
C#
<authentication mode="Forms">
<forms loginUrl="~/LogIn.aspx" protection="All" slidingExpiration="true" timeout="2880"</authentication>

At masterpage
C#
protected void Page_Load(object sender, EventArgs e)
   {       
       if (!HttpContext.Current.User.Identity.IsAuthenticated)
       {
          Response.Redirect("~/LogIn.aspx");
       }
}
protected void HeadLoginStatus_LoggedOut(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
 Response.Redirect(@"~/Login.aspx", false);
    }

pls help its urgent and i cant solve it..check is it write or not..
Posted

1 solution

You have to use Session Timeout to do this. Check
here[^]
 
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