Link to home
Start Free TrialLog in
Avatar of Bob Schneider
Bob SchneiderFlag for United States of America

asked on

Creating Cookies in Classic ASP Site

I want to create cookies for a Remember Me functionality on http://www.gtraxc.com/login.asp

Here is how I create the cookie:
            If Request.Form.Item("remember-me") = "on" Then
                Response.Cookies("user_name") = sUserName
                Response.Cookies("password") = sPassword
            End If

Open in new window


Here is where I retrieve it:
sUserName = Request.Cookies("user_name")
sPassword = Request.Cookies("password")

Open in new window


And here is how I attempt to place it in the appropriate form item values:
                                <fieldset class="form-group position-relative has-icon-left">
                                    <input type="text" class="form-control form-control-lg input-lg" 
                                    name="user_name" id="user_name" placeholder="Your User Name" required=""
                                    value="<%=sUserName%>">
                                    <div class="form-control-position">
                                        <i class="icon-head"></i>
                                    </div>
                                </fieldset>
                                <fieldset class="form-group position-relative has-icon-left">
                                    <input type="password" class="form-control form-control-lg input-lg" 
                                    name="password" id="user-password" placeholder="Enter Password" required=""
                                    value="<%=sPassword%>" aria-invalid="false">
                                    <div class="form-control-position">
                                        <i class="icon-key3"></i>
                                    </div>
                                </fieldset>

Open in new window


It does not appear to be working.  Any help would be much appreciated.
Avatar of zc2
zc2
Flag of United States of America image

You do not specify the expiration date. So, once the user closes the browser your cookies will disappear.
Try to trace the cookie creation and posting back using the F12 developer tool or Telerik Fiddler.
Avatar of Bob Schneider

ASKER

Thank you.  What is a reasonable expiration time limit for cookies?  Is there an industry standard?
I am not aware of a standard. I usually set that to a month.
No there is no standard as it is highly dependent on use case.

Setting an expiration time is optional - if you don't set it the cookie dies with the session (when you close the browser) - for some applications that is desirable.

A remember me does not fall into that category.

You need to decide how long you want to remember a user for (day, week, month) - I usually set it for a month and refresh it on logon.
I can't seem to get the user name and password box to populate.  Here is how I am creating the cookies now:
                Response.Cookies("user_name") = sUserName
                Response.Cookies("password") = sPassword

                Response.Cookies("user_name").Expires=#March 1, 2020#
                Response.Cookies("password").Expires=#March 1, 2020#

Open in new window


Also, can I incorporate a variable into the expiration?  Something like Date + 30
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial