【问题标题】:Jquery cookie plugin not working on serverJquery cookie插件在服务器上不起作用
【发布时间】:2013-06-30 22:30:29
【问题描述】:

我是 jquery cookie 插件的新手。 我正在编写代码以在一个页面服务器端设置 cookie 并从 jquery 的另一个页面上读取它。 它在所有浏览器上本地工作。 但在服务器上它可以在 ie 上正常工作,而不能在 chrome 和 firefox 上正常工作。 这是我在服务器端设置 cookie 的代码:

context.Response.AppendCookie(new HttpCookie("fileDownloadToken", _token));

并在使用 jquery 在另一个页面上下载文件后读取和删除 cookie:

  <script type="text/javascript">

    var fileDownloadCheckTimer;
    function blockUIForDownload() {
        var token = '1357.11.22'; 
        $('#download_token_value').val(token);
       $.blockUI({
            message:$('#domMessage'),
            css: {
                padding: 10,
                margin: 0,
                width: '30%',
                top: '50%',
                left: '35%',

                textAlign: 'center',
                color: '#000',
                border: '3px solid #aaa',
                backgroundColor: '#fff',
                cursor: 'wait',
            }});
            fileDownloadCheckTimer = window.setInterval(function () {
                var cookieValue = $.cookie('fileDownloadToken');
                //alert(cookieValue);
                if (cookieValue == token)
                    finishDownload();
            }, 1000);
    }

    function finishDownload() {
        window.clearInterval(fileDownloadCheckTimer);
        $.unblockUI();
        $.cookie('fileDownloadToken', null, { path: '/' });

    }

</script>  

【问题讨论】:

    标签: c# asp.net cookies session-cookies jquery-cookie


    【解决方案1】:

    请设置 cookie 过期日期时间,因为服务器可能位于浏览器系统时间之后的另一个时区。

    HttpCookie cookie = new HttpCookie("fileDownloadToken", _token);
    cookie.Expires = DateTime.Now.AddMinutes(10); //change this to appropriate value
    cookie.Path = "/"; //Also set path
    context.Response.AppendCookie(cookie);
    

    【讨论】:

      猜你喜欢
      • 2011-01-06
      • 2016-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-03
      相关资源
      最近更新 更多