namespace Web.Controls.ConLogin
{
public partial class UserLogin1 : System.Web.UI.UserControl
{ //建立cookie
System.Web.HttpCookie newcookie = new HttpCookie("user");
Model.User myUser = new Model.User();
BLL.UserBLL myUserBLL = new UserBLL();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ //判断Cookies是否存在
if (Response.Cookies["user"]["userName2"]!= null)
{//判断用户名存在
if (myUserBLL.CheckUserName(Response.Cookies["userName2"].Value.ToString()))
Response.Redirect("~/Test2.aspx");
}
}
}
protected void LinkLogin1_Click(object sender, EventArgs e)
{
//验证码
if (txtPic1.Text == Request.Cookies["CheckCode"].Value)
{ //用户名和密码验证.
string uid;
string pwd; uid = Server.HtmlDecode(txtName1.Text); pwd = Server.HtmlDecode(txtPass1.Text);
myUser.userName = uid;
myUser.userPassword = pwd;
if (myUserBLL.BLLCheckUser (uid ,pwd ))
{
//用户是否选择记住cookie
if (remberCookies.Checked == true)
{ if ( Response.Cookies["userName2"].Value == null)
{
newcookie.Values["userName2"] = txtName1.Text.Trim();
newcookie.Values["userPass2"] = txtPass1.Text.Trim();
newcookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(newcookie); //Response.Cookies["userName1"].Value = txtName1.Text.Trim();
//Response.Cookies["userPass1"].Value = txtPass1.Text.Trim();
//Response.Cookies["userName1"].Expires = DateTime.Now.AddDays(1);
//Response.Cookies["userPass1"].Expires = DateTime.Now.AddDays(1);
}}
}
}
{
public partial class UserLogin1 : System.Web.UI.UserControl
{ //建立cookie
System.Web.HttpCookie newcookie = new HttpCookie("user");
Model.User myUser = new Model.User();
BLL.UserBLL myUserBLL = new UserBLL();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ //判断Cookies是否存在
if (Response.Cookies["user"]["userName2"]!= null)
{//判断用户名存在
if (myUserBLL.CheckUserName(Response.Cookies["userName2"].Value.ToString()))
Response.Redirect("~/Test2.aspx");
}
}
}
protected void LinkLogin1_Click(object sender, EventArgs e)
{
//验证码
if (txtPic1.Text == Request.Cookies["CheckCode"].Value)
{ //用户名和密码验证.
string uid;
string pwd; uid = Server.HtmlDecode(txtName1.Text); pwd = Server.HtmlDecode(txtPass1.Text);
myUser.userName = uid;
myUser.userPassword = pwd;
if (myUserBLL.BLLCheckUser (uid ,pwd ))
{
//用户是否选择记住cookie
if (remberCookies.Checked == true)
{ if ( Response.Cookies["userName2"].Value == null)
{
newcookie.Values["userName2"] = txtName1.Text.Trim();
newcookie.Values["userPass2"] = txtPass1.Text.Trim();
newcookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(newcookie); //Response.Cookies["userName1"].Value = txtName1.Text.Trim();
//Response.Cookies["userPass1"].Value = txtPass1.Text.Trim();
//Response.Cookies["userName1"].Expires = DateTime.Now.AddDays(1);
//Response.Cookies["userPass1"].Expires = DateTime.Now.AddDays(1);
}}
}
}
cookie实例名.Empires=DateTime.Now.AddMonth(3);
if ( Response.Cookies["userName2"].Value == null)
{
newcookie.Values["userName2"] = txtName1.Text.Trim();
newcookie.Values["userPass2"] = txtPass1.Text.Trim();
newcookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(newcookie);
估计是if ( Response.Cookies["userName2"].Value == null) 的问题
{
//得到用户输入的用户名
newcookie.Values["userName2"] = txtName1.Text.Trim();
//得到用户输入的密码
newcookie.Values["userPass2"] = txtPass1.Text.Trim();
这里你可以尝试修改为:
Response.AppendCookie(newcookie);