• 大小: 8KB
    文件类型: .zip
    金币: 2
    下载: 0 次
    发布日期: 2021-05-24
  • 语言: C#
  • 标签: ASP.NET  C#  

资源简介

使用ASP.NET建站时,登录模块中常用的技术,解决了客户重复输入的用户名和密码比较麻烦的问题,实用性很强。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class login : System.Web.UI.Page
{
    //页面加载时执行的内容 Start
    protected void Page_Load(object sender EventArgs e)
    {
        //第一次加载不满足条件,之后均满足,将Cookie数据输出到TextBox里
        if(Request.Cookies[“username“]!=null&&Request.Cookies[“password“]!=null)
        {
            TextBox1.Text = Request.Cookies[“username“].Value.ToString();
            TextBox2.Text = Request.Cookies[“password“].Value.ToString();
        }
    }
    //页面加载时执行的内容 End
    //重置按钮的功能的实现 Start
    protected void Button2_Click1(object sender EventArgs e)
    {
        this.FindButton(this);
    }
    private void FindButton(Control c)
    {
        if (c.Controls != null)
        {
            foreach (Control x in c.Controls)
            {
                if (x is System.Web.UI.WebControls.TextBox)
                {
                    ((System.Web.UI.WebControls.TextBox)x).Text = ““;
                }
                FindButton(x);
            }
        }
    }
    //重置按钮的功能的实现 End
    //登录按钮的功能的实现 Satrt
    protected void Button1_Click(object sender EventArgs e)
    {
        if (CheckBox1.Checked)
        {
            //创建Cookie对象,保存Cookie数据,设置Cookie保存时间
            Response.Cookies[“username“].Value = TextBox1.Text;
            Response.Cookies[“username“].Expires = DateTime.Now.AddSeconds(10);
            Response.Cookies[“password“].Value = TextBox2.Text;
            Response.Cookies[“password“].Expires = DateTime.Now.AddSeconds(10);
            Response.Redirect(“Test.aspx“);
        }
    }
    //登录按钮的功能的实现 End
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-10-31 20:27  ASP.NET中登录时记住用户名和密码\
     目录           0  2017-10-31 20:27  ASP.NET中登录时记住用户名和密码\demo\
     文件         409  2017-10-31 17:50  ASP.NET中登录时记住用户名和密码\demo\Test.aspx
     文件         276  2017-10-31 17:49  ASP.NET中登录时记住用户名和密码\demo\Test.aspx.cs
     文件        1306  2017-10-31 13:16  ASP.NET中登录时记住用户名和密码\demo\Web.Debug.config
     文件         362  2017-10-31 13:16  ASP.NET中登录时记住用户名和密码\demo\Web.config
     文件         870  2017-10-31 19:26  ASP.NET中登录时记住用户名和密码\demo\login.aspx
     文件        1930  2017-10-31 20:26  ASP.NET中登录时记住用户名和密码\demo\login.aspx.cs
     文件        1670  2017-10-31 20:26  ASP.NET中登录时记住用户名和密码\localhost_2422.sln
     文件       24576  2017-10-31 20:26  ASP.NET中登录时记住用户名和密码\localhost_2422.v11.suo

评论

共有 条评论