in my asp.net web application,merchant once logged in to the web application in mozilla browser or other browsers and close that browser.Open the same browser and give log in url,it should not go to log in page;it must go to next page as like gmail,yahoo
..etc
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessService;
using BuinessObjects;
using BuinessObjects.Collections;
using CommonDataService;
namespace Shop
{
public partial class Merchant_Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (HttpContext.Current.Request.Cookies["MerchantLoginCookie"] != null)
{
txtLoginEmail.Text = HttpContext.Current.Request.Cookies["MerchantLoginCookie"]["LoginName"].ToString();
string Password = HttpContext.Current.Request.Cookies["MerchantLoginCookie"]["Password"].ToString();
txtPassword.Attributes.Add("value", Password);
}
}
}
protected void btnLogin_Click(object sender, EventArgs e)
{
try
{
if (chkRememberMe.Checked)
{
HttpCookie cookie = new HttpCookie("MerchantLoginCookie");
cookie.Values.Add("LoginName", txtLoginEmail.Text);
cookie.Values.Add("Password", txtPassword.Text);
cookie.Expires = DateTime.Now.AddDays(30);
Response.Cookies.Add(cookie);
}
User objUser = new User();
objUser.EmailID = txtLoginEmail.Text.Trim();
objUser.Password = txtPassword.Text.Trim();
if (UserService.ValidateEmailID(objUser)==1)
{
if (objUser.Password == txtPassword.Text.Trim())
{
Session["Role"] = "Merchant";
Session["EmailID"] = txtLoginEmail.Text.Trim();
objUser.EmailID = Session["EmailID"].ToString();
Session["UserName"] = objUser.UserName;
Session["UserID"] = objUser.UserID;
Response.Redirect("~/Merchant/Merchant-CreateProfile.aspx", false);
}
else
{
WebMsgBox.Show(Messages.strInvalidPwd);
return;
}
}
else
{
WebMsgBox.Show(Messages.strInvalidEmail);
txtLoginEmail.Text = "";
return;
}
}
catch (Exception ex)
{
CommonLog.Save_ErrorLog("Login.aspx", "ValidateUser", ex);
}
}
}
}
Above is my code.Please tel ur opinion that how can i achieve this?how should maintain session as like gmail,yahoo in my asp.net web application?pls guide me friends...
heaartly thanks for replying my post.I have tried this whatever you given friend but
merchant once logged in to the web application in mozilla browser or other browsers and close that browser.Open the same browser and give log in url,it should not go to log in page;[it must go to next page as like gmail,yahoo ..etc]but it going to log
in page
hello friend SohailShaikh,
thanks for your reply friend.as per your advise im getting the output .
but now what i want is i need to make below cookie value = null
ttpContext.Current.Request.Cookies["MerchantLoginCookie"].Value != null)
how to do this friend?
pls guide me friends.
girikas
Member
67 Points
321 Posts
how to maintain session like gmail ,yahoo in my asp.net web application?
Aug 24, 2012 04:56 AM|LINK
in my asp.net web application,merchant once logged in to the web application in mozilla browser or other browsers and close that browser.Open the same browser and give log in url,it should not go to log in page;it must go to next page as like gmail,yahoo ..etc
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using BusinessService; using BuinessObjects; using BuinessObjects.Collections; using CommonDataService; namespace Shop { public partial class Merchant_Login : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (HttpContext.Current.Request.Cookies["MerchantLoginCookie"] != null) { txtLoginEmail.Text = HttpContext.Current.Request.Cookies["MerchantLoginCookie"]["LoginName"].ToString(); string Password = HttpContext.Current.Request.Cookies["MerchantLoginCookie"]["Password"].ToString(); txtPassword.Attributes.Add("value", Password); } } } protected void btnLogin_Click(object sender, EventArgs e) { try { if (chkRememberMe.Checked) { HttpCookie cookie = new HttpCookie("MerchantLoginCookie"); cookie.Values.Add("LoginName", txtLoginEmail.Text); cookie.Values.Add("Password", txtPassword.Text); cookie.Expires = DateTime.Now.AddDays(30); Response.Cookies.Add(cookie); } User objUser = new User(); objUser.EmailID = txtLoginEmail.Text.Trim(); objUser.Password = txtPassword.Text.Trim(); if (UserService.ValidateEmailID(objUser)==1) { if (objUser.Password == txtPassword.Text.Trim()) { Session["Role"] = "Merchant"; Session["EmailID"] = txtLoginEmail.Text.Trim(); objUser.EmailID = Session["EmailID"].ToString(); Session["UserName"] = objUser.UserName; Session["UserID"] = objUser.UserID; Response.Redirect("~/Merchant/Merchant-CreateProfile.aspx", false); } else { WebMsgBox.Show(Messages.strInvalidPwd); return; } } else { WebMsgBox.Show(Messages.strInvalidEmail); txtLoginEmail.Text = ""; return; } } catch (Exception ex) { CommonLog.Save_ErrorLog("Login.aspx", "ValidateUser", ex); } } } }Above is my code.Please tel ur opinion that how can i achieve this?how should maintain session as like gmail,yahoo in my asp.net web application?pls guide me friends...
SohailShaikh
Contributor
6129 Points
1172 Posts
Re: how to maintain session like gmail ,yahoo in my asp.net web application?
Aug 24, 2012 05:09 AM|LINK
They all are maintain there session in cookies but there is limit of cookies you can use only 20 cookies
and please make empty all cookies when user click on logout button
Sohail Shaikh
girikas
Member
67 Points
321 Posts
Re: how to maintain session like gmail ,yahoo in my asp.net web application?
Aug 24, 2012 05:26 AM|LINK
HttpCookie cookie = new HttpCookie("logincookie");
cookie.Value = "merch";
cookie.Expires = DateTime.Now.AddDays(1);
i added cookie to my login page.but in (!ispostback) function it showing cookie.value = null;how to solve this error?
pls guide me friends
SohailShaikh
Contributor
6129 Points
1172 Posts
Re: how to maintain session like gmail ,yahoo in my asp.net web application?
Aug 24, 2012 05:28 AM|LINK
Ok download the example program from my skydrive
https://skydrive.live.com/?cid=2F22272220E37707&id=2F22272220E37707%21103
Program name is Remember me
Sohail Shaikh
girikas
Member
67 Points
321 Posts
Re: how to maintain session like gmail ,yahoo in my asp.net web application?
Aug 24, 2012 06:00 AM|LINK
hello SohailShaikh,
thanks for ur reply and file sharing friend.i use ur code also but its not working friend..
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using BuinessObjects; using BuinessObjects.Collections; using BusinessService; using CommonDataService; namespace ShopMonkey.Admin { public partial class Login : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Response.Cookies["Name"].Value != null) { Response.Redirect("~/Admin/Merchant.aspx", false); } if (HttpContext.Current.Request.Cookies["LoginCookie"] != null) { txtUserName.Text = HttpContext.Current.Request.Cookies["LoginCookie"]["LoginName"].ToString(); string Password = HttpContext.Current.Request.Cookies["LoginCookie"]["Password"].ToString(); txtPassword.Attributes.Add("value", Password); } } } #region Login Validation protected void btnLogin_Click(object sender, EventArgs e) { try { if (chkRemember.Checked) { HttpCookie cookie = new HttpCookie("LoginCookie"); cookie.Values.Add("LoginName", txtUserName.Text); cookie.Values.Add("Password", txtPassword.Text); cookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(cookie); } User objUser = new User(); UserList objUserList = new UserList(); objUser.UserName = txtUserName.Text.Trim(); objUser.Password = Security.Encryption(txtPassword.Text.Trim()); objUserList = UserService.ValidateAdminUser(objUser); if (objUserList.Count == 1) { if (objUserList[0].RoleID == 1) { Session["Role"] = "Admin"; Session["Log"] = 1; Response.Cookies["Name"].Value = objUser.UserName; Response.Cookies["Name"].Expires = DateTime.Now.AddMonths(1); Session["AdminUserID"] = objUserList[0].UserID; Response.Redirect("~/Admin/Merchant.aspx", false); } else { WebMsgBox.Show(Messages.strNotAuthorize); txtUserName.Text = ""; txtPassword.Text = ""; } } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "ValidateUser", "alert('Invalid');", true); txtUserName.Text = ""; txtPassword.Text = ""; return; } } catch (Exception ex) { CommonLog.Save_ErrorLog("Login.aspx", "ValidateUser", ex); } } #endregion } }i changed the coding as like above.pls guide me friend.how to resolve this error?
SohailShaikh
Contributor
6129 Points
1172 Posts
Re: how to maintain session like gmail ,yahoo in my asp.net web application?
Aug 24, 2012 06:14 AM|LINK
Sohail Shaikh
girikas
Member
67 Points
321 Posts
Re: how to maintain session like gmail ,yahoo in my asp.net web application?
Aug 24, 2012 06:23 AM|LINK
hi SohailShaikh,
heaartly thanks for replying my post.I have tried this whatever you given friend but merchant once logged in to the web application in mozilla browser or other browsers and close that browser.Open the same browser and give log in url,it should not go to log in page;[it must go to next page as like gmail,yahoo ..etc]but it going to log in page
how to resolve this friend?
pls guide me friends
SohailShaikh
Contributor
6129 Points
1172 Posts
Re: how to maintain session like gmail ,yahoo in my asp.net web application?
Aug 24, 2012 06:30 AM|LINK
send my your complete programe orignal on my email i will solve this and send you back
ssohail@sunbonn.com
Sohail Shaikh
girikas
Member
67 Points
321 Posts
Re: how to maintain session like gmail ,yahoo in my asp.net web application?
Aug 24, 2012 08:35 AM|LINK
hello friend SohailShaikh, thanks for your reply friend.as per your advise im getting the output . but now what i want is i need to make below cookie value = null ttpContext.Current.Request.Cookies["MerchantLoginCookie"].Value != null) how to do this friend? pls guide me friends.SohailShaikh
Contributor
6129 Points
1172 Posts
Re: how to maintain session like gmail ,yahoo in my asp.net web application?
Aug 24, 2012 08:58 AM|LINK
if you want the value null of this cookiess now
then use this on logout method
Response.Cookies["URL"].Value = null;
Sohail Shaikh