Hi all. I am trying to write a cookie onto the client that I want to last for 1 month. I have been using -
<% .......
-
var hdata= [what i want to save];
-
exdate=new Date;
-
exdate.SetMonth(exdate.GetMonth()+1);
-
Response.Cookies("myname")="History="+hdata;
-
Response.Cookies("myname").Expires=exdate;
-
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
8 18806
Hi all. I am trying to write a cookie onto the client that I want to last for 1 month. I have been using -
<% .......
-
var hdata= [what i want to save];
-
exdate=new Date;
-
exdate.SetMonth(exdate.GetMonth()+1);
-
Response.Cookies("myname")="History="+hdata;
-
Response.Cookies("myname").Expires=exdate;
-
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 - 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
I always used Response.Cookies("myname").Expires=dateadd("m", 1, now())
or "d" for days, "h" hours, "n" minutes, "s" seconds
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
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.
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
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
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
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: - futureDate = dateAdd("m", 1, date())
-
expDate = formatDateTime(futureDate, 1)
-
...
-
response.cookies("test").expires=exDate;
now I guess you will have to try to convert this to jscript... good luck
Jared
Sign in to post your reply or Sign up for a free account.
Similar topics
by: |
last post by:
Its strange...I have experimenting with browser hawk by using the cookie
sniffer method. However, even If adjust the security slider level in
internet options or goto advanced in the privacy tab I...
|
by: Retlak |
last post by:
The recommended (on dozens of websites) and effective (works in
Netscape, MSIE, Mozilla, probably others) way to detect if a browser
has Javascript turned off is to put this in the <head>:
...
|
by: What-a-Tool |
last post by:
I am using a couple of session variables in my site. From what I can figure
out, session information is stored on the users computer in a cookie -
If the user has cookies disabled, do session...
|
by: Adam |
last post by:
I'm trying to track who's logged into a site (without setting flags in
the databses).
At the moment, each user gets a cookie with "Usr_Name" set if
authentication goes through OK.
Is there a...
|
by: Don |
last post by:
Hi,
When passing serialized object's XML from ASP.NET to a SQL Server 2k
sproc, what format should
I have the text in?
Here's my XML:
<ArrayOfEmployee...
|
by: Water Cooler v2 |
last post by:
I am practicing Cookies in .NET. Its working fine but when I want to
clear my cookies, the statement,
Response.Cookies.Clear
does not work. What gives?
Here's what I do:
|
by: Phillip N Rounds |
last post by:
I'm having trouble with using cookies to monitor the stages of login.
I have a two stage Registration page ( register.aspx ) and my target page
( MyPage.aspx )
I'm using a cookie named LoginStatus...
|
by: yawnmoth |
last post by:
Say I wrote an ajax script to send out HTTP requests via ajax. Any
cookies that I have associated with that site will be sent along with
this HTTP request. Is there a way to prevent this from...
|
by: damezumari |
last post by:
To find out were session variables are stored I included this
instruction in my program:
echo ini_get("session.save_path");
The reply was /home/7604/data/tmp which is a folder on my server.
I...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |