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>

  • 相关阅读:
    (基础) --- KMP字符串
    (基础)--- 前缀和、差分
    PHOTOSHOP --- 分辨率、图片保存格式
    Oracle Delete数据后手动释放空间
    掌握爬虫技术需要学哪些内容?
    如何用python制作动态二维码,来哄女朋友开心?
    python为什么会环境变量设置不成功
    python和js交互调用的方法
    基于PHP实现解密或加密Cloudflar邮箱保护
    基于pytorch中的Sequential用法说明
  • 原文地址:https://www.cnblogs.com/duanlinlin/p/3143049.html
Copyright © 2011-2022 走看看