Solved

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

Posted on 2016-07-21
8
43 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
  • 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
 

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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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
 

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
 

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
 

Author Closing Comment

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

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 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