cookie.aspx.cs

来自「关于ASP.NET制作程序模块」· CS 代码 · 共 54 行

CS
54
字号
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnlog_Click(object sender, EventArgs e)
    {
        string name = "admin";
        string pass = "admin";
        if (this.TextBox1.Text == "admin" && this.TextBox2.Text == "admin")
        {
            if (this.RadioButtonList1.SelectedValue.ToString() == "1")
            {
                this.Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(1);
                this.Response.Cookies["Password"].Expires = DateTime.Now.AddDays(1);
            }
            if (RadioButtonList1.SelectedValue.ToString() == "2")
            {
                this.Response.Cookies["UserName"].Expires = DateTime.Now.AddMonths(1);
                this.Response.Cookies["Password"].Expires = DateTime.Now.AddMonths(1);
            }
            if (RadioButtonList1.SelectedValue.ToString() == "3")
            {
                this.Response.Cookies["UserName"].Expires = DateTime.Now.AddYears(1 / 2);
                this.Response.Cookies["Password"].Expires = DateTime.Now.AddYears(1 / 2);
            }
            if (RadioButtonList1.SelectedValue.ToString() == "4")
            {
                this.Response.Cookies["UserName"].Expires = DateTime.Now.AddYears(1);
                this.Response.Cookies["Password"].Expires = DateTime.Now.AddYears(1);
            }
            this.Response.Cookies["UserName"].Value = this.TextBox1.Text;
            this.Response.Cookies["Password"].Value = this.TextBox2.Text;
            Response.Redirect("getcookie.aspx");
        }
        else
        {
            Response.Redirect("cookie.aspx");
        }
        
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?