我的登陆控件log.ascx文件如下:
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="log.ascx.cs" Inherits="myEdu.log" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<table cellSpacing="1" cellPadding="2" width="100%" border="0" bgcolor="#ccffff">
<%
if(Session["UserName"] == null)
{
%>
<tr>
<td align="right" width="40%">用户名:</td>
<td><asp:textbox id="txtName" Runat="server" Height="20px" Width="80px"></asp:textbox></td>
</tr>
<tr>
<td align="right" width="40%">密码:</td>
<td>
<asp:textbox id="txtPass" runat="server" TextMode="Password" Height="20px" Width="80px"></asp:textbox>
</td>
</tr>
<tr>
<td align="right" width="40%">登陆信息:</td>
<td>
<asp:dropdownlist id="dListCookie" runat="server" Height="20px" Width="80px">
<asp:ListItem Value="0" Selected="True">不保存</asp:ListItem>
<asp:ListItem Value="1">保存一周</asp:ListItem>
</asp:dropdownlist></td>
</tr>
<tr>
<td width="100%" height="5" colspan="2"></td>
</tr>
<tr>
<td align="right" width="50%">
<asp:imagebutton id="btnLogin" runat="server" ImageUrl="image/login.gif"></asp:imagebutton> </td>
<td align="left">
<asp:imagebutton id="btnReg" runat="server" ImageUrl="image/reg.gif"></asp:imagebutton></td>
</tr>
<% }
else
{
%>
<tr>
<td width="100%" align="center">
<b><font color="#ff0000">
<%=Session["UserName"]%>
:</font></b>你好!欢迎登陆<br>
<br>
祝您学习愉快!<br>
<br>
<asp:Button ID="btnOut" Runat="server" Text="退出" />
<a href="userinfo.aspx">个人信息</a>
</td>
<% }
%>
</tr>
</table>
//我的log.ascx.xs文件如下:
namespace myEdu
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls; /// <summary>
/// log 的摘要说明。
/// </summary>
public class log : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.TextBox txtName;
protected System.Web.UI.WebControls.TextBox txtPass;
protected System.Web.UI.WebControls.DropDownList dListCookie;
protected System.Web.UI.WebControls.ImageButton btnLogin;
protected System.Web.UI.WebControls.Button btnOut;
protected System.Web.UI.WebControls.ImageButton btnReg; private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(Request.Cookies["UserInfo"]!=null && Request.Cookies["UserInfo"]["UserName"]!="")
{
Session["UserName"]=Request.Cookies["UserInfo"]["UserName"];
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnLogin.Click += new System.Web.UI.ImageClickEventHandler(this.btnLogin_Click);
this.btnReg.Click += new System.Web.UI.ImageClickEventHandler(this.btnReg_Click);
this.btnOut.Click += new System.EventHandler(this.btnOut_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void btnReg_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Redirect("login.aspx");
} private void btnLogin_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(txtName.Text=="pwqzc" && txtPass.Text=="cn0088")
{
Session["UserName"] = txtName.Text;
if(dListCookie.SelectedItem.Value=="1")
{
Response.Cookies["UserInfo"]["UserName"]=txtName.Text;
Response.Cookies["UserInfo"].Expires = DateTime.Now.AddDays(7);
}
Response.Redirect(Request.Url.ToString());//重新导向到原请求页面
}
else
{
Response.Write("<script>alert('登陆失败!用户名或者密码错误!');</script>");
}
} private void btnOut_Click(object sender, System.EventArgs e)
{
Request.Cookies["UserInfo"]["UserName"]="";
Request.Cookies["UserInfo"].Expires=new DateTime(1979,10,1);
Session["UserName"] = null;
//Response.Redirect(Request.Url.ToString());
}
}
}当我在页面中引用他的时候一切正常,但是当我点退出按钮退出登陆的时候,在点其他的连接,在其他页面的登陆控件中显示的依然是登陆信息而不是用户登陆框!!!明显的我已经清除了cookie啊?这是什么会事啊,昨天晚上一个晚上也没有搞好啊,请指教
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="log.ascx.cs" Inherits="myEdu.log" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<table cellSpacing="1" cellPadding="2" width="100%" border="0" bgcolor="#ccffff">
<%
if(Session["UserName"] == null)
{
%>
<tr>
<td align="right" width="40%">用户名:</td>
<td><asp:textbox id="txtName" Runat="server" Height="20px" Width="80px"></asp:textbox></td>
</tr>
<tr>
<td align="right" width="40%">密码:</td>
<td>
<asp:textbox id="txtPass" runat="server" TextMode="Password" Height="20px" Width="80px"></asp:textbox>
</td>
</tr>
<tr>
<td align="right" width="40%">登陆信息:</td>
<td>
<asp:dropdownlist id="dListCookie" runat="server" Height="20px" Width="80px">
<asp:ListItem Value="0" Selected="True">不保存</asp:ListItem>
<asp:ListItem Value="1">保存一周</asp:ListItem>
</asp:dropdownlist></td>
</tr>
<tr>
<td width="100%" height="5" colspan="2"></td>
</tr>
<tr>
<td align="right" width="50%">
<asp:imagebutton id="btnLogin" runat="server" ImageUrl="image/login.gif"></asp:imagebutton> </td>
<td align="left">
<asp:imagebutton id="btnReg" runat="server" ImageUrl="image/reg.gif"></asp:imagebutton></td>
</tr>
<% }
else
{
%>
<tr>
<td width="100%" align="center">
<b><font color="#ff0000">
<%=Session["UserName"]%>
:</font></b>你好!欢迎登陆<br>
<br>
祝您学习愉快!<br>
<br>
<asp:Button ID="btnOut" Runat="server" Text="退出" />
<a href="userinfo.aspx">个人信息</a>
</td>
<% }
%>
</tr>
</table>
//我的log.ascx.xs文件如下:
namespace myEdu
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls; /// <summary>
/// log 的摘要说明。
/// </summary>
public class log : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.TextBox txtName;
protected System.Web.UI.WebControls.TextBox txtPass;
protected System.Web.UI.WebControls.DropDownList dListCookie;
protected System.Web.UI.WebControls.ImageButton btnLogin;
protected System.Web.UI.WebControls.Button btnOut;
protected System.Web.UI.WebControls.ImageButton btnReg; private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(Request.Cookies["UserInfo"]!=null && Request.Cookies["UserInfo"]["UserName"]!="")
{
Session["UserName"]=Request.Cookies["UserInfo"]["UserName"];
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnLogin.Click += new System.Web.UI.ImageClickEventHandler(this.btnLogin_Click);
this.btnReg.Click += new System.Web.UI.ImageClickEventHandler(this.btnReg_Click);
this.btnOut.Click += new System.EventHandler(this.btnOut_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void btnReg_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Redirect("login.aspx");
} private void btnLogin_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(txtName.Text=="pwqzc" && txtPass.Text=="cn0088")
{
Session["UserName"] = txtName.Text;
if(dListCookie.SelectedItem.Value=="1")
{
Response.Cookies["UserInfo"]["UserName"]=txtName.Text;
Response.Cookies["UserInfo"].Expires = DateTime.Now.AddDays(7);
}
Response.Redirect(Request.Url.ToString());//重新导向到原请求页面
}
else
{
Response.Write("<script>alert('登陆失败!用户名或者密码错误!');</script>");
}
} private void btnOut_Click(object sender, System.EventArgs e)
{
Request.Cookies["UserInfo"]["UserName"]="";
Request.Cookies["UserInfo"].Expires=new DateTime(1979,10,1);
Session["UserName"] = null;
//Response.Redirect(Request.Url.ToString());
}
}
}当我在页面中引用他的时候一切正常,但是当我点退出按钮退出登陆的时候,在点其他的连接,在其他页面的登陆控件中显示的依然是登陆信息而不是用户登陆框!!!明显的我已经清除了cookie啊?这是什么会事啊,昨天晚上一个晚上也没有搞好啊,请指教
解决方案 »
- 关于Fckeditor拖拽的问题--------急急急
- 请教VB.NET ,如何让光标一点在TextBox框即弹出一个日历选择框可以选择日期,选了后Textbox中显示的是2008/12/21这种式样的
- 当前系统日期怎么也插不进去
- 请问: 我怎么在CodeFile文件中用不了SQL
- [window.open], 父窗口如何控制弹出的子窗口,注意:不是子窗口控制父窗口。
- 菜鸟用c#开发asp.net,但不知如何实现树状图,是不是需要下载呢??在哪下载呢??
- 为什么在保存缩率图的时候经常会出现这种错误?
- datagrid绑定的数据的删除问题(代码如下)
- rowfilter表达式的问题?
- 按EXCEL表的格式一模一样的绑定数据 我该怎么办
- 如何才能使输出的格式与输入的格式一样呢?
- 有关datalist及radioButtonList
或者退出时清空客户端缓存