最近写了个登陆的用户控件.ascx文件利用Session保存登陆信息和判断是否显示登陆框
.ascx.cs中
Response.Write("<script language=javascript>alert('你已经成功登陆!');</script>");
Session["memberlogin"] = "OK"; //保存登陆信息到Session变量
Session["membername"] = pu;
Session["memberpass"] = pw;
Response.Redirect("index.aspx");
}
else
{
Response.Write("<script language=javascript>alert('非法登录!');</script>");
}并且在.ascx文件中
<%
if (Session["memberlogin"]=="")
{
%>
<td>
用户名:<asp:TextBox runat="server" ID="TextBox_usertext" ></asp:TextBox>
密 码:<asp:TextBox runat="server" ID="TextBox_userpass" TextMode="Password"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" Height="20px"
ImageUrl="~/image/login.jpg" Width="60px" OnClick="ImageButton1_Click" />
<asp:ImageButton ID="ImageButton2"
runat="server" Height="20px" ImageUrl="~/image/exit.jpg" Width="60px" OnClick="ImageButton2_Click"/>
</td>
<%
}
else
{
%>为什么出现错误提示说,当前上下文中缺少Session
麻烦高手帮忙解决下……在线等待
.ascx.cs中
Response.Write("<script language=javascript>alert('你已经成功登陆!');</script>");
Session["memberlogin"] = "OK"; //保存登陆信息到Session变量
Session["membername"] = pu;
Session["memberpass"] = pw;
Response.Redirect("index.aspx");
}
else
{
Response.Write("<script language=javascript>alert('非法登录!');</script>");
}并且在.ascx文件中
<%
if (Session["memberlogin"]=="")
{
%>
<td>
用户名:<asp:TextBox runat="server" ID="TextBox_usertext" ></asp:TextBox>
密 码:<asp:TextBox runat="server" ID="TextBox_userpass" TextMode="Password"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" Height="20px"
ImageUrl="~/image/login.jpg" Width="60px" OnClick="ImageButton1_Click" />
<asp:ImageButton ID="ImageButton2"
runat="server" Height="20px" ImageUrl="~/image/exit.jpg" Width="60px" OnClick="ImageButton2_Click"/>
</td>
<%
}
else
{
%>为什么出现错误提示说,当前上下文中缺少Session
麻烦高手帮忙解决下……在线等待
解决方案 »
- webrequest cookie 的获取问题
- asp.net页面级事务怎么写啊,我给忘了,加急
- [求助] 服务器控件Menu如何去掉“展开指示符”?
- 正则表达式问题
- 向各位请教如何在datagrid控件的头部加上CheckBox复选框
- 大家用的是哪种AJAX组件
- 有人在搞2005的Reporting Service吗?交流一下QQ:89148614
- 急问:关于SqlCommand的问题!!!!!????????
- 列名'XX'无效???
- 我要把DataSet的数据写入XML文件,但这个XML文件需要先用程序创建,才能添加节点。但最上面那句话怎么创建啊。
- Microsoft OLE DB Provider for ODBC Drivers 错误 '80040e37' 望高手解决
- asp.net 怎么写了访问数据库的线程
protected void Page_Load(object sender, EventArgs e)
{
if (session["userName"] = null)
{
}
}
<%
if (Session["memberlogin"]=="")
{
%>
当你在后台的地方没有给Session["membgerlogin"]赋过值的时候,它本身默认的值是一个null,而你直接拿它去跟一个字符串来比较是不行的,你只能先确定好它不是null后再进行比较,试试
<%
if (Session["memberlogin"] == null)
{
%>