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>

  • 相关阅读:
    GetHub下载不成功
    Cache 判断Ip几分钟内攻击次数
    .net 通过Url获取站点json数据
    Linq 读取Xml 数据
    ef Linq 自定义字段列表
    面试的心得
    触发器--单独字段变化另一个字段也变化
    Ajax跨域 取值 Jsonp的定义注意事项
    asp.net里,各种下载方式汇总
    c# 获取硬件信息
  • 原文地址:https://www.cnblogs.com/duanlinlin/p/3143049.html
Copyright © 2011-2022 走看看