我如何在页面中保存Cookie [英] how can i save cookies in pages

查看:150
本文介绍了我如何在页面中保存Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.

我想从当前页面移至另一页面,所以我使用了以下代码:

Hi.

i want to move from current page to another page so i used this code:

Response.Redirect("~/Education.aspx");



但是我的问题是,当用户在浏览器中按Back时,上一页会释放他的cookie,并且该页的文本框中不会有任何数据.



but my problem is when user press Back in Browser , the previous page looses his cookies and there won''t be any data inside textbox in page.

推荐答案

尝试以下代码:
You can try following code:
protected void Page_Load(object sender, EventArgs e)
{
  if (Request.Cookies["Email"] != null)
  {
     txtEmail.Text = Request.Cookies["Email"].Value;
  }
}

protected void btnSubmit_Click(object sender, EventArgs e)
{
  Response.Cookies["Email"].Value = txtEmail.Text;
  Response.Cookies["Email"].Expires = DateTime.Now.AddDays(30);
}



或浏览给定的页面链接:
使用RememberMe CheckBox和ASP.Net中的Cookie [



Or Go through given page link:
Remember UserName and Password using RememberMe CheckBox and Cookies in ASP.Net[^]

All the best.


请参考:
嗨.我想知道cookie的代码,如何在在线投票应用程序中使用cookie [ ASP.NET Cookie入门指南 [ ^ ]
Please refer:
hi.. i want know the code for cookies, how to use cookies in online polling application[^]
Beginner''s Guide to ASP.NET Cookies[^]



发生这种情况是因为您没有提供Expires
的cookie
Hi ,
Well this happen because you didn''t supply cookies with Expires
Response.Cookies["test"].Expires = DateTime.Now.AddYears(1);


检查此
http://www.aspnettutorials.com/tutorials/network/cookies-csharp.aspx [ ^ ]
http://www.dotnetfunda.com/articles/article1404-how- to-read-cookies-in-aspnet.aspx [ ^ ]
ASP.NET中的Cookie [有关ASP.NET C#中Cookie的所有信息 [ ^ ]
http://msdn.microsoft.com/en-us/library/ms178194.aspx [ ^ ]
最好的问候
米特瓦里(M.Mitwalli)


Check this
http://www.aspnettutorials.com/tutorials/network/cookies-csharp.aspx[^]
http://www.dotnetfunda.com/articles/article1404-how-to-read-cookies-in-aspnet.aspx[^]
Cookies in ASP.NET[^]
all thing about cookies in asp.net c#[^]
http://msdn.microsoft.com/en-us/library/ms178194.aspx[^]
Best Regards
M.Mitwalli


这篇关于我如何在页面中保存Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆