C#Asp.net得到Cookie的到期时间在JavaScript总是返回01.01.0001设置 [英] c# Asp.net getting Cookie expiration time set in javascript always returns 01.01.0001

查看:511
本文介绍了C#Asp.net得到Cookie的到期时间在JavaScript总是返回01.01.0001设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JavaScript函数存储cookie的:

I use a javascript function to store the cookie:

createCookie("teaser", "teaser", 7);
function createCookie(name, value, days) {
var expires = "";
if (days) {
    var date = new Date();
    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
    expires = "; expires=" + date.toGMTString();
}
document.cookie = name + "=" + value + expires + "; path=/";
return value;
}

而当我检查cookies在我的浏览器传情的cookie有效期设置正确:
25.十月2011十六点12分17秒。

And when I check the cookies in my browser the cookie expiration of teaser is correctly set: 25. oktober 2011 16:12:17

但是,当在C#我去得到的价值,到期日期设置为01.01.0001。

But when in C# i go to get the value, the expiration date is set to 01.01.0001.

    var cookie = Request.Cookies["teaser"];
    if (cookie != null && teaserList.Count() > 0)
    {

        cookie.Expires is 01.01.0001

任何线索?

推荐答案

<一个href=\"http://www.eggheadcafe.com/tutorials/asp-net/198ce250-59da-4388-89e5-fce33d725aa7/aspnet-cookies-faq.aspx\"相对=nofollow>理论家说:

浏览器负责管理Cookie和cookie的
  到期时间和日期帮助浏览器管理其饼干店。
  因此,虽然可以读取Cookie的名称和值,
  无法读取Cookie的到期日期和时间。当浏览器
  发送cookie信息到服务器,该浏览器不包括
  过期的信息。 (cookie的Expires属性始终
  返回零日期时间值)。如果你关心
  一个cookie的有效期,则必须重新设置。

The browser is responsible for managing cookies, and the cookie's expiration time and date help the browser manage its store of cookies. Therefore, although you can read the name and value of a cookie, you cannot read the cookie's expiration date and time. When the browser sends cookie information to the server, the browser does not include the expiration information. (The cookie's Expires property always returns a date-time value of zero.) If you are concerned about the expiration date of a cookie, you must reset it.

这篇关于C#Asp.net得到Cookie的到期时间在JavaScript总是返回01.01.0001设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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