博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
设置Session超时
阅读量:7071 次
发布时间:2019-06-28

本文共 1210 字,大约阅读时间需要 4 分钟。

登录页:

前台:

 <div>

    用户:<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox><br />
    密码:<asp:TextBox ID="txtPwd" runat="server"></asp:TextBox><br />
        <asp:Button ID="Button1" runat="server" Text="登录" οnclick="Button1_Click" />
    </div>

后台:

protected void Button1_Click(object sender, EventArgs e)

        {
            if (txtUserName.Text=="admin"&&txtPwd.Text=="888888")
            {
                Session["username"] = txtUserName.Text;
                Response.Redirect("WebBlock.aspx");
            }
        }

跳转的页子(ps:将注册信息写入到文本中):

 <div>

        <asp:TextBox ID="TextBox1" runat="server" Height="382px" TextMode="MultiLine" 
            Width="478px"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="保存"  οnclick="Button1_Click" />
    </div>

后台:

protected void Button1_Click(object sender, EventArgs e)

        {
            if (Session["username"] != null)
            {
                FileStream stream = File.Open(@"d:\1.txt", FileMode.OpenOrCreate, FileAccess.Write);
                StreamWriter writer = new StreamWriter(stream);
                writer.Write(TextBox1.Text);
                writer.Dispose();
                stream.Dispose();
            }
            else
            {
                Response.Redirect("Error.aspx");
            }
        }

Web.config中设置时间:

<system.web>

        <compilation debug="true" targetFramework="4.0" />
      <sessionState timeout="1"/>
    </system.web>

查实后跳转的页子Error页:

 <div>

    登录超时,请重新登录。
    </div>

转载于:https://www.cnblogs.com/duanlinlin/p/3143049.html

你可能感兴趣的文章
ECharts测量图,功率图
查看>>
个人总结作业
查看>>
C++的预处理(Preprocess)
查看>>
仿网易菜单 实现侧滑 SlidingMenu
查看>>
延时显示的三种实现方式
查看>>
LeetCode算法题-Missing Number(Java实现-四种解法)
查看>>
Quick Cocos2dx 与 EnterFrame事件
查看>>
一个用ASP生成html的新方法
查看>>
Selenium学习之==>Switch与SelectApi接口详解
查看>>
Js判断是否是直接进入本页面的
查看>>
GOlang eclipse install
查看>>
Centos7 hostname重启失效
查看>>
Postgre SQL连接服务器失败
查看>>
小程序之短信验证
查看>>
App Store优化推广 如何提高海外搜索排名
查看>>
POJ3580 SuperMemo(Splay的区间操作)
查看>>
Android Service解析
查看>>
CentOS7-部署kubernetes
查看>>
hdu 4001 To Miss Our Children Time( sort + DP )
查看>>
日常note
查看>>