Solved

Updating the Expiry time on a Cookie

Posted on 2008-06-17
11
635 Views
Last Modified: 2012-06-21
Hi all,

Once a cookie has been created using ASP, is it possible to update it's expiry time?
I would like to keep updating a cookie whilst a user is using the Web Site, but expire after 3 minutes of inactivity.

I am using ASP under WinCE 5.0, so I don't think that 'Session' is available...

Any thoughts would be appreciated.

Best regards,

James
0
Comment
Question by:jatkin
  • 6
  • 5
11 Comments
 
LVL 15

Expert Comment

by:dosth
ID: 21804077
Try:
Response.Cookies("cookiename").expires=Dateadd("n" , 3, Now())
0
 
LVL 4

Author Comment

by:jatkin
ID: 21804249
Hi,

Thanks for the info. I have tried this and I get the following error...

The collection object specified is read-only
ASP scripting compilation error: '80020009'
Description:
In file: Security.asp
On line: 29

Any thoughts? Am I doing something stupid??? :-O

James
0
 
LVL 15

Expert Comment

by:dosth
ID: 21804379
do you have the cookie added in yor code already

use that "cookiename" instead of this
0
 
LVL 4

Author Comment

by:jatkin
ID: 21810850
Hi,
I updated the cookie name to match mine.
I have attached the code for the Login.asp (takes the login info) and the Securit.asp (included on all pages to ensure the valid credentials)
SECURITY.ASP*********************************

<%

      intDoHome = 1

      if (intDoHome = 1) then 

%>

<%

' *** Restrict Access To Page: Grant or deny access to this page

MM_authorizedUsers="1,2"

MM_authFailedURL="login.asp"

MM_grantAccess=false
 

If Request.Cookies("MM_Username") <> "" Then

  If (false Or CStr(Request.Cookies("MM_UserAuthorization"))="") Or _

         (InStr(1,MM_authorizedUsers,Request.Cookies("MM_UserAuthorization"))>=1) Then

    MM_grantAccess = true

  End If

End If
 

If MM_grantAccess Then

    Response.Cookies("MM_Username").Expires = DateAdd("s", 120, now())

    Response.Cookies("MM_UserID").Expires = DateAdd("s", 120, now())

End If
 
 

If Not MM_grantAccess Then

  MM_qsChar = "?"

  If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"

  MM_referrer = Request.ServerVariables("URL")

  x_strRequestQueryString = Request.QueryString

  if (Len(x_strRequestQueryString) > 0) Then MM_referrer = MM_referrer & "?" & x_strRequestQueryString

  MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)

  Response.Redirect(MM_authFailedURL)

End If

%>

<%

      End if 

%>
 
 
 
 

LOGIN.ASP****************************************
 

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<%Response.Buffer = True%>

<!--#include file="conn.asp" -->

<!--#include file="SQLConst.asp" -->

<!--#include file="SQLFunctions.asp" -->

<!--#include file="GeneralFunctions.asp" -->
 

<%

' *** Validate request to log in to this site.

MM_LoginAction = Request.ServerVariables("URL")
 

x_strRequestQueryString = Request.QueryString

If x_strRequestQueryString<>"" Then MM_LoginAction = MM_LoginAction + "?" + xServer.HTMLEncode(Request.QueryString)

MM_valUsername=CStr(Request.Form("username"))

If MM_valUsername <> "" Then

      MM_fldUserAuthorization="intAccessLevel"

      MM_redirectLoginSuccess="home.asp"

      MM_redirectLoginFailed="failed.asp"

      MM_flag="ADOCE.Recordset.3.1"

      Set cn = CreateObject("ADOCE.Connection.3.1")

      set MM_rsUser = CreateObject(MM_flag)

      cn.Open MM_conn_STRING

      MM_rsUser.Source = "SELECT txtUsername, txtPassword, intUserID"

      If MM_fldUserAuthorization <> "" Then MM_rsUser.Source = MM_rsUser.Source & "," & MM_fldUserAuthorization

      MM_rsUser.Source = MM_rsUser.Source & " FROM tblUsers WHERE txtUsername='" & Replace(MM_valUsername,"'","''") &"' AND txtPassword='" & Replace(Request.Form("password"),"'","''") & "'"

      MM_rsUser.Open MM_rsUser.Source, cn, adOpenStatic, adLockReadOnly
 

      If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then

            ' username and password match - this is a valid user

            Response.Cookies("MM_Username") = MM_valUsername

            Response.Cookies("MM_UserID") = MM_rsUser("intUserID")

            

            'Response.cookies("MM_Username").expires = Date + 1

            'Response.cookies("MM_UserID").expires = Date + 1
 

            Response.Cookies("MM_Username").Expires = DateAdd("s", 120, now())

            Response.Cookies("MM_UserID").Expires = DateAdd("s", 120, now())
 
 

            If (MM_fldUserAuthorization <> "") Then

                  Response.Cookies("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)

            Else

                  Response.Cookies("MM_UserAuthorization") = ""

            End If
 

            if CStr(Request.QueryString("accessdenied")) <> "" And true Then

                  MM_redirectLoginSuccess = Request.QueryString("accessdenied")

            End If

            MM_rsUser.Close

            Response.Redirect(MM_redirectLoginSuccess)

      End If

      MM_rsUser.Close

      Response.Redirect(MM_redirectLoginFailed)

End If

%>

Open in new window

0
 
LVL 15

Expert Comment

by:dosth
ID: 21810874
can you tell mw what is the issue with your current code?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Author Comment

by:jatkin
ID: 21810878
When it gets to the :

If MM_grantAccess Then
    Response.Cookies("MM_Username").Expires = DateAdd("s", 120, now())
    Response.Cookies("MM_UserID").Expires = DateAdd("s", 120, now())
End If

it fails with "ASP scripting compilation error: '80020009'" as above
0
 
LVL 15

Expert Comment

by:dosth
ID: 21810955
if you comment the cookies line, it is okay?

i see no issues with the code
0
 
LVL 4

Author Comment

by:jatkin
ID: 21810979
It all works fine without that code, however the cookie expires after 3 minutes - even if the user is using the interface.

What I want is to update the expiry every time a user interacts with the interface, therefore it expires after 3 minutes of inactivity.
0
 
LVL 15

Accepted Solution

by:
dosth earned 500 total points
ID: 21811184
If MM_grantAccess Then
    Response.Cookies("MM_Username") = Request.Cookies("MM_Username")
    Response.Cookies("MM_UserID")   = Request.Cookies("MM_UserID")
    Response.Cookies("MM_Username").Expires = DateAdd("s", 120, now())
    Response.Cookies("MM_UserID").Expires = DateAdd("s", 120, now())
End If
0
 
LVL 4

Author Closing Comment

by:jatkin
ID: 31597259
Excellent! Thanks!!!
0
 
LVL 15

Expert Comment

by:dosth
ID: 21811309
thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iis reverse proxy virtual directory 8 134
SQL Query Join 9 61
Sorting - Classic asp putting a specific text @ the top of the table 3 40
Forcing form refresh - classic ASP 7 59
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

861 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

Need Help in Real-Time?

Connect with top rated Experts

29 Experts available now in Live!

Get 1:1 Help Now