Solved

Getting and Setting Cookies

Posted on 2012-03-29
2
283 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 83

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
disable data migrations in visual studio 2017 4 48
Can Angular be used with classic asp.net? 3 33
Get sourcecode path 14 47
Header Font Size in Grid View 6 26
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

749 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