当前位置:开发者网络 >> 技术教程 >> .NET教程 >> 数据库应用 >> 内容
精彩推荐
分类最新教程
分类热点教程
  
读取和设置cookie的一个函数
作者:未知
日期:2004-12-24
人气:
投稿:snow(转贴)
来源:未知
字体:
收藏:加入浏览器收藏
以下正文:
前提准备条件:

1。你要有2个TextBox控件,一个用来输密码,一个用来输用户名,不过好想这些都是必需的,

2。你要有一个 RadioButtonList 控件,用来设置Cookie的存活时间。关于内部值得设置是:年y,月m,星期w,天d,浏览器进程p。

3。好了,现在你就可以在网页pageload中嵌入以下代码了:

注意:据说asp.net中,没有内置的设置Focus的方法,请自己使用javascript 控件名.Focus实现



public void check(System.Web.UI.WebControls.TextBox tb,System.Web.UI.WebControls.RadioButtonList choose)
{
HttpCookie hc = Request.Cookies["TestCookie"];
if(hc !=null)
tb.Text = hc.Value;
else
{
hc = new HttpCookie("TestCookie",tb.Text);
DateTime dt =DateTime.Now;
TimeSpan ts = new TimeSpan(365,0,0,0);
if(choose.SelectedItem.Value =="y")
ts = new TimeSpan(365,0,0,0);
else if(choose.SelectedItem.Value =="m")
ts = new TimeSpan(30,0,0,0);
else if(choose.SelectedItem.Value =="w")
ts = new TimeSpan(7,0,0,0);
else if(choose.SelectedItem.Value =="d")
ts = new TimeSpan(1,0,0,0);
hc.Expires = dt.Add(ts);
Response.Cookies.Add(hc);
}
}
相关文章: