01-24-2007, 02:31 PM
Doing a 4 page web app for online shopping
The first page requires a name and email address which both have to be validated first which I've done but I need to save both pieces of information as cookies on the client machine for the period of the session, I've tried a variety of things but the info does not appear automatically when I run the program, both pieces of info are in server texbox controls
Any ideas on this would be appreciated as I'm new to Asp.Net
01-24-2007, 04:07 PM
If you wanted to store some values in a cookie, you'd say:
Dim loginCookie As HttpCookie = New HttpCookie("Login")
loginCookie.Expires = #1/4/2009#
So that would store a username and password from the respective text boxes. They are now stored in a category called 'Login'. You can add as many values to the collection as you want but I've just used two in that example. To then read those back you would say:
Label1.Text = "Hello " & Request.Cookies("Login")("username")
So you see you have to specify the category and the key to retrieve the data back again.
My example is flawed in your situation because I have not used any encryption and if you are storing credentials for an online store you really should encrypt the cookie. Check out the tutorial below for more info on encrypting a cookie.
01-24-2007, 09:29 PM
Actually just store the informaiton in sessions variables. Then a SessionID cookie will automatically be stored, but the username and password will never leave the server. They will sit happily in memory until the session times out.
If you're using it for authentication, you may also want to look into the FormsAuthentication class. It handles some of the nitty-gritty for you.
01-26-2007, 12:55 PM
Thanks mcdonnc204 for your help
The second form needs to display the products in a data grid, the products list needs to be created as an XML file, this will be loaded into a dataset available to all users of the application, the data grid also needs to contain buttons to add to the shopping cart, on selection of one of these buttons the program will store the description and price of the item in session variables to be used by the next page
I've tried creating the XML file for example
Code for 2nd form load event procedure
Dim strPath As String = Server.MapPath(".")
Dim dsUsers as new dataset
dsusers.readxmlschema(strPath & "\products.xsd")
dsusers.readxml(strPath & "\products.xml")
I can't get the datagrid to appear in the second form is there something wrong with the coding, any help would be appreciated
01-27-2007, 06:31 AM
XML files need to have a root node. try changing your file (and schema) to something like this. (spacing optional. just here so you can see the relationship.)
It would also help if you told us what was happening. What error message are you getting? etc... Otherwise we're just guessing.
01-27-2007, 08:54 AM
Thanks for the reply
Understand your point on XML which I've done now however I still can't get the datagrid to appear in the 2nd form, I am not getting an error just a blank page on the 2nd form
I've used the same coding in the previous post for the 2nd form load event procedure and added DataGrid1.DataBind but still nothing iappears is there something else I'm missing here
Thanks for your help