Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-07-21
8
Medium Priority
?
87 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 36

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 36

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 36

Assisted Solution

by:ste5an
ste5an earned 2000 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

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!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

885 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