zoukankan      html  css  js  c++  java
  • 设置Session超时

    登录页:

    前台:

     <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="登录" onclick="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="保存"  onclick="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>

  • 相关阅读:
    Spring Security -- 添加图形验证码(转载)
    Spring Security -- 自定义用户认证(转载)
    pandas agg 后降低df表层
    判断是否有人跟踪车辆的方案
    格隆汇笔记-黄勇演讲
    Mac mysql 忘记root密码的解决方法
    sql 同步2个表中的一个字段数据
    Linux下配置用msmtp和mutt发邮件
    spark StructType的应用,用在处理mongoDB keyvalue
    Idea2018旗舰版破解方法
  • 原文地址:https://www.cnblogs.com/duanlinlin/p/3143049.html
Copyright © 2011-2022 走看看