Solved

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

Posted on 2016-07-21
8
69 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

617 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