Solved

set expiration date cookie problem, it's in past.

Posted on 2016-07-21
8
57 Views
Last Modified: 2016-08-02
I want two write a cookie that expires in 7 days.
But it doesn't function, I couldn't find the cookie. I found out that I had to add 103 days extra to the expire date

with this line Response.Cookies ("GUID2").Expires = DATE + 110 the cookie expires in 7 days.

The behaviour on one virtual win2012 server. I tested the code on other servers and there it works like it should. But every site on this 2012 server I have to add extra days.

This is the code:
asp file
Function CreateGuid()
    CreateGuid = Left(CreateObject("Scriptlet.TypeLib").Guid,38)
End Function

Function CreateGuidCookie(renew)
	If Request.Cookies ("GUID2") = "" or renew = true Then
		Response.Cookies ("GUID2") = CreateGuid
		Response.Cookies ("GUID2").Expires = DATE + 7
	End If
	CreateGuidCookie = request.Cookies ("GUID2")
End Function

Function ExtendGuidCookie
	Response.Cookies .Expires = DATE + 7
End Function

Open in new window

asp.net file
<%
Response.Cookies["UserSettings"]["Font"] = "Arial";
Response.Cookies["UserSettings"]["Color"] = "Blue";
Response.Cookies["UserSettings"].Expires = DateTime.Now.AddDays(1d);
%>

Open in new window

So I guess I am looking for a setting on the server.. timing of the server is ok.
0
Comment
Question by:Richard Frank
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 33

Expert Comment

by:ste5an
ID: 41724194
What is DATE? Looks like a constant.
0
 
LVL 6

Expert Comment

by:worthyking1
ID: 41724734
That is very odd. How about trying to workaround the odd server settings by specifically setting your expire date with DateAdd function (where you can force the date/time unit being added) and then putting that into the cookie.

Like so:

ExpireDate = DateAdd("d",7,DATE)
Response.Cookies("GUID2").Expires = ExpireDate

Open in new window

0
 
LVL 1

Author Comment

by:Richard Frank
ID: 41724843
first, thanks for the response
a response.write "date = " & DATE returns me date today like it should

@worthyking1
I tried it but unfortunately .. still had to add 110 (7 + 103)  days the generate a cookie that expires in 7 days.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 33

Expert Comment

by:ste5an
ID: 41724943
And what does
response.write "date = " & DateAdd("d",7,Date())

Open in new window

return?
Also test
response.write "date = " & CDate(DateAdd("d",7,Date()))

Open in new window

and
response.write "date = " & FormatDateTime(DateAdd("d",7,Date()) ,1)

Open in new window

.

And also test formatting the date value for your cookie using an explicit US format (mm/dd/yyyy).
0
 
LVL 1

Author Comment

by:Richard Frank
ID: 41731078
I'm sorry, took long till I had time again. colleagues on holiday etc.

respectively these response writes returns
date = 03/08/2016
date = 03/08/2016
date = miércoles, 03 de agosto de 2016
0
 
LVL 33

Assisted Solution

by:ste5an
ste5an earned 500 total points
ID: 41731109
hmm, then I'm pretty clueless. cause the code itself seems to be okay.

How did you find out that you needed to add 110? btw, can you us a proxy like Fiddler to intercept the HTTP traffic to see what your ASP application is sending?
0
 
LVL 1

Accepted Solution

by:
Richard Frank earned 0 total points
ID: 41731200
Thnx.. Fiddler helped me to find something odd.. what it already is :)

A server where it is working.. raw headers output
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 123
Content-Type: text/html
Server: Microsoft-IIS/8.5
Set-Cookie: GUID2=%7B4A92DF78%2D1AF4%2D43DD%2DBDC9%2DAC37400C3AF5%7D; expires=Tue, 02-Aug-2016 22:00:00 GMT; path=/
Set-Cookie: ASPSESSIONIDQEDDASDB=DGKPPAFAIPPNLNCCAHMKGFGD; secure; path=/
X-Powered-By: ASP.NET
X-UA-Compatible: IE=edge
Date: Wed, 27 Jul 2016 12:40:49 GMT correct


HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 123
Content-Type: text/html
Server: Microsoft-IIS/8.5
Set-Cookie: GUID2=%7BF48A9E0F%2DE8D6%2D466E%2D9FBB%2D0020FF348DC2%7D; expires=Tue, 02-Aug-2016 22:00:00 GMT; path=/
Set-Cookie: ASPSESSIONIDCCARARQD=HFJJEDFAFNMAOBNLNODLDGJJ; path=/
X-Powered-By: ASP.NET
Date: Tue, 01 Nov 2016 08:01:56 GMT
wrong date :S

that I googled and I found
http://serverfault.com/questions/217343/date-header-returned-by-iis7-is-wrong

after stopping / starting http and iisreset the timing in the cookies are correct.
0
 
LVL 1

Author Closing Comment

by:Richard Frank
ID: 41738721
ste5an helped me find my own solution.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Returning a value from a class function to a partial view in MVC5 7 46
Designing forms 3 43
Multi-Column Repeater 3 24
Broken .resx file generating errors 18 16
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question