编写ASP.net website程序(cookies)
发布网友
发布时间:2022-04-27 15:45
我来回答
共2个回答
热心网友
时间:2022-04-27 17:14
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class test1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["username"]!=null )
{
TextBox1.Visible = false;
TextBox2.Visible = false;
Button1.Visible = false;
int vinum;
if (Request.Cookies["vinum"] = null)
{
vinum = 0;
}
else
{
vinum = Convert.ToInt32(Request.Cookies["vinum"].Value);
vinum += 1;
}
Response.Cookies["vinum"].Value =vinum.ToString() ;
Response.Write("欢迎你的到来!" + Request.Cookies["username"].Value + "!你是第" + vinum + "次访问此页!");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Cookies["username"].Value = TextBox1.Text;
}
}
热心网友
时间:2022-04-27 18:32
写:
HttpCookie cookie =new HttpCookie ("user");
cookie.Values.Add ("userID",check_userid);
cookie.Expires=DateTime.Now.AddDays(100);
Response.AppendCookie (cookie);
读:
HttpCookie cookie= Request.Cookies ["user"];
string user_id=cookie.Values["userID"];
参考资料:http://www.alixixi.com/Dev/Web/ASPNET/aspnet3/2007/2007050734415.html