• 创建cookie


    cookie的创建
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace AspDotNet04
    {
    public partial class C10CookieLogin : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    if (Request.HttpMethod.ToLower() == "post")
    {
    string strN = Request.Form["txtN"];
    string strP = Request.Form["txtP"];
    //登录成功
    if (strN == "admin" && strP == "123")
    {
    //创建Cookie,存入 键值对
    HttpCookie cookie = new HttpCookie("cname",strN);
    //设置失效时间(硬盘Cookie) - 2分钟
    cookie.Expires = DateTime.Now.AddMinutes(2);
    //设置cookie的Path
    //cookie.Path = "/admin/";
    //cookie.Domain = "www.baidu.com";
    //加入响应报文对象
    Response.Cookies.Add(cookie);

    //让浏览器 重定向 到首页
    Response.Redirect("C11CookieIndex.aspx");
    //Response.Redirect("/admin/CookieIndex.aspx");
    }
    }
    }
    }
    }

  • 相关阅读:
    codeforces 980A Links and Pearls
    zoj 3640 Help Me Escape
    sgu 495 Kids and Prizes
    poj 3071 Football
    hdu 3853 LOOPS
    hdu 4035 Maze
    hdu 4405 Aeroplane chess
    poj 2096 Collecting Bugs
    scu 4444 Travel
    zoj 3870 Team Formation
  • 原文地址:https://www.cnblogs.com/kexb/p/3660397.html
Copyright © 2020-2023  润新知