By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,237 Members | 505 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,237 IT Pros & Developers. It's quick & easy.

ASP cookies().Expires= (what format?)

P: 10
Hi all. I am trying to write a cookie onto the client that I want to last for 1 month. I have been using
Expand|Select|Wrap|Line Numbers
  1. <%  .......
  2. var hdata= [what i want to save];
  3. exdate=new Date;
  4. exdate.SetMonth(exdate.GetMonth()+1);
  5. Response.Cookies("myname")="History="+hdata;
  6. Response.Cookies("myname").Expires=exdate;
  7. Response.Cookies("myname").Secure=false; ....... 
but the problem is that, I get a runtime error 800a000d , "Type Mismatch" for the line that has
...Expires=exdate. So, how can I create a cookie that will last for a month, what format of the date is it looking for?
hthfys,
Coachdave
Jun 28 '07 #1
Share this Question
Share on Google+
8 Replies

jhardman
Expert 2.5K+
P: 3,405
Hi all. I am trying to write a cookie onto the client that I want to last for 1 month. I have been using
Expand|Select|Wrap|Line Numbers
  1. <%  .......
  2. var hdata= [what i want to save];
  3. exdate=new Date;
  4. exdate.SetMonth(exdate.GetMonth()+1);
  5. Response.Cookies("myname")="History="+hdata;
  6. Response.Cookies("myname").Expires=exdate;
  7. Response.Cookies("myname").Secure=false; ....... 
but the problem is that, I get a runtime error 800a000d , "Type Mismatch" for the line that has
...Expires=exdate. So, how can I create a cookie that will last for a month, what format of the date is it looking for?
hthfys,
Coachdave
try
Expand|Select|Wrap|Line Numbers
  1. Response.Cookies("myname").Expires=now() + 30
(or 31) or you can do a tricky calculation to figure out how many days are in the current month, but that seems a bit too laborious when you can just say it expires "now() + 30"

(I think this is right. at least, I don't want to look too foolish)

Jared
Jun 29 '07 #2

danp129
Expert 100+
P: 321
I always used Response.Cookies("myname").Expires=dateadd("m", 1, now())

or "d" for days, "h" hours, "n" minutes, "s" seconds
Jun 29 '07 #3

P: 10
Thank you for the suggestions, but I am still getting error messages.
I try
Response.Cookies("rtest1").Expires=dateadd("m",1,n ow());
and get
error 800a138f Object expected
I try
Response.Cookies("rtest1").Expires=now()+30 ;
and get
error 800a138f Object expected
I try
Response.Cookies("rtest1").Expires="exdate";
and get
error 800a000d Type mismatch (same as original attempt)
I try
Response.Cookies("rtest1').Expires="dateadd('m',1, now())";
and get
error 800a000d Type mismatch .
Anyone have any other suggestions?
Coachdave
Jul 6 '07 #4

danp129
Expert 100+
P: 321
response.cookies******** belongs within <% %> tags not in <script></script> tags. From the looks of things you are attempting to run this as a javascript instead of server-side ASP.
Jul 6 '07 #5

P: 10
I am running this on a server as server-side asp, BUT: you should know: I start out the page with
<%@Language=JScript%>
and much of the code, which works, is in fact javascript. What I am trying to add to the working code is this code about the cookie. I have found that, notwithstanding the errors, the cookie is being set - so the expiration time of the cookie is at least a few minutes.
In the past people have suggested statements like
set name= [the definition of....]
and also after a file variable has been declared and used,
set filename = nothing
but these have always produced error messages on my server, and I have assumed that is because these are vbscript syntax and dont compile in jscript.
When I use things like
var sqhist=""+Request.Form("qhist");
it compiles and runs correctly.
So - I set my cookie with
Response.Cookies("rtest1')="Testname"+tdata;
where tdata is defined in a previous statement. How do I make the cookie I set expire in one month? Coachdave
Jul 19 '07 #6

jhardman
Expert 2.5K+
P: 3,405
I found this code example at a jsp tutorial site. Apparently in JSP the cookie life span is an integer number of seconds. go figure. I don't read jsp very well, so I'm not sure if this has what you are looking for, but let me know. click here

Jared
Jul 19 '07 #7

P: 10
Jared - and all others interested:
I dont know whether jsp is asp running Jscript or not, the code in your examples does not look familiar. At any rate, when I tried to use your example for setting a cookie, that is,
c=new Cookie("User"" etc. );
c,setMaxAge(60*24*60*60);
response.addCookie(c);
I get an error message 800a1391, "Cookie" is undefined, on the first line of that.
What does work is a suggestion from www.w3schools.com/asp.
Response.Cookies("test")=rdata;
Response.Cookies("test").Expires="July 29, 2007";
a LITERAL date. Elsewhere w3schools defines Expires as a Property, says it sets how long IN MINUTES "a page will be cached", but said nothing about cookies. When I tried
... .Expires=4400;
to get 3 days, I got an error message to the effect that I had tried to set a date "outside of the range of January 1, 1980 and October 13, 2038". Go figure. I could use the literal date method, but I would always have be going in and changing it. Anyone know a better way that works?
Coachdave
Jul 26 '07 #8

jhardman
Expert 2.5K+
P: 3,405
I could use the literal date method, but I would always have be going in and changing it. Anyone know a better way that works?
Coachdave
No you don't, just make a literal date string in your page and use that to set the expire date:
Expand|Select|Wrap|Line Numbers
  1. futureDate = dateAdd("m", 1, date())
  2. expDate = formatDateTime(futureDate, 1)
  3. ...
  4. response.cookies("test").expires=exDate;
now I guess you will have to try to convert this to jscript... good luck

Jared
Jul 27 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.