Solved

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

Posted on 2016-07-21
8
61 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 34

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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 34

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 34

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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Use Mid in Html 6 35
orderby list (from Json) 1 44
asp.net repeater 2 38
EF5: Update Model from Database not working 3 83
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…

739 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