Solved

Getting and Setting Cookies

Posted on 2012-03-29
2
273 Views
Last Modified: 2012-03-29
Can anyone provide two scripts for getting and setting cookies.  The cookie name is "synkfba" and it will contain username and password.

If need to check to see if the cookie exists and if not create it.

Thanks.
0
Comment
Question by:sherbug1015
2 Comments
 
LVL 4

Accepted Solution

by:
elliottbenzle earned 500 total points
ID: 37782876
I think you will need to set separate cookies for user and password:

<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub SubmitBtnWrite_Click(Sender As Object, E As EventArgs)
        Response.Cookies("synkfba").Expires = "5/1/2013"
        Response.Cookies("synkfba").Value = _
            "User_name"
        Response.Cookies("synkfba-password").Expires = "5/1/2013"
        Response.Cookies("synkfba-password").Value = _
            "User_password."
End Sub
Sub SubmitBtnRead_Click(Sender As Object, E As EventArgs)
    Dim I as integer
    For I = 0 to Request.Cookies.Count - 1
        lblMessage1.Text = lblMessage1.Text  _
            & Request.Cookies.Item(I).Name & ": " _
            & Request.Cookies.Item(I).Value & "<BR>"
    Next
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Cookies Sample Page</TITLE>
</HEAD>
<BODY >
<form runat="server">
<Font Face="Tahoma">
<asp:Label
    id="lblMessage1"
    runat="Server"
    Font-Bold="True"
/>
<BR><BR>
<asp:button
    id="butOK1"
    runat="server"
    text="Write Cookies to Browser"
    Type="Submit"
    OnClick="SubmitBtnWrite_Click"
/>
<asp:button
    id="butOK2"
    runat="server"
    text="Read Cookies from Browser"
    Type="Submit"
    OnClick="SubmitBtnRead_Click"
/>
</Font>
</Form>
</BODY>
</HTML>
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 37783507
It is considered very insecure and bad practice to store usernames and passwords in cookies because that makes them available to anyone who uses that computer.  Cookies stored on the computer are just text files that can be easily read.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

9 Experts available now in Live!

Get 1:1 Help Now