Home > Forum > ASP.NET > Log in, Log out...

Log in, Log out...

by Jeevaraj   on Feb 15, 2012   Category: ASP.NET  |  Views: 2048    |  Points: 5   |  Starter 
  Reply
Can anyone of u tell me the code to Log in and Log out....


I tried many ways but they didn't provide the full authentication... My project should has the following...
1.An user login in a IE browser. After log in, if the user request the login page again in another IE browser my project should use the same login info and should get into the site... it should not request the username and password again...
2.After get logout it should not give access to the website while clicking the back button of the browser...

If u can, Can u send me the entire code to login and logout....


Bookmark and Share:
 
  User Reply  | Ask a question  |   Reply 
  Re :Log in, Log out...   
by Spidy
on Feb 23 2012 4:06AM
Points : 10
Silver 
Hello Jeeav,

Below is the one of the way to achieve you requirement

1. Use cookie to store the user details.
2. Check user details in the cookie if once open the new browser.
3. When user clicks on the logout clear the cookie details and after that user needs to provide the credentials to login into application.

place the below code in login page.
protected void Login_Click(object sender, EventArgs e)
{
if (authenticate(txtName.Text, txtPwd.Text))
{
if (ChckRemember.Checked == true)
{
Response.Cookies["UsrName"].Value = txtName.Text;
Response.Cookies["UsrPWD"].Value = txtPwd.Text;
Response.Cookies["UsrName"].Expires = DateTime.Now.AddMonths(6);
Response.Cookies["UsrPWD"].Expires = DateTime.Now.AddMonths(6);
}
}

private bool authenticate(string name, string pwd)
{
//check user cred..
return true;

}

place the below code in login page or home page
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.Cookies["UsrName"] != null && Request.Cookies["UsrPWD"] != null)
{
if (authenticate(Request.Cookies["UsrName"].Value, Request.Cookies["UsrPWD"].Value))
{
Response.Redirect("test.aspx");
}
}
}
}

see the below URL for logout and avoid back button ..

http://www.dotnetgallery.com/lab/resource47-Avoid-back-button-after-logout-in-aspnet-application.aspx

Thanks.

Recent Post

Latest Posts