Solved

Cookie returning null error

Posted on 2006-11-20
4
232 Views
Last Modified: 2010-05-18
1.I have saved 2 values in a cookie like this:
If Request.Cookies("LoginSettings") Is Nothing Then
            Response.Cookies("LoginSettings")("DB") = rbDatabases.SelectedItem.Value
            Response.Cookies("LoginSettings")("Language") = rbLan.SelectedItem.Value
            Response.Cookies("LoginSettings").Expires = DateTime.Now.AddDays(7)
        End If

2. I go to my cookie folder and I see the cookie values:
   LoginSettings DB=SQL&Language=English localhost\<bunch of numbers here>

3. Want to read them back:
 If Not Page.IsPostBack Then
            If Request.Cookies("LoginSettings") IsNot Nothing Then
                If Request.Cookies("LoginSettings")("DB") IsNot Nothing Then
                   rbSystems.SelectedItem.Value = Request.Cookies("LoginSettings")("DB")  ****This line returns null***
                End If
                If Request.Cookies("LoginSettings")("Language") IsNot Nothing Then
                    rbLan.SelectedItem.Value = Request.Cookies("Language").Value.ToString

                End If

            End If
        End If


***But I keep getting Null Error on rbSystems.SelectedItem.Value = Request.Cookies("LoginSettings")("DB").
what am i missing?

0
Comment
Question by:Camillia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
bprojoe earned 500 total points
ID: 17980595
Try something like this......

If Request.Cookies("LoginSettings") Is Nothing Then
dim cookie as new httpcookie("LoginSetting")
cookie.values("DB") = rbDatabases.SelectedItem.Value
            cookie.values("Language") = rbLan.SelectedItem.Value
            cookie.values.Expires = DateTime.Now.AddDays(7)
Response.AppendCookie(cookie)
else
dim cookie as httpcookie = request.cookies("LoginSetting")
cookie.values("DB") = rbDatabases.SelectedItem.Value
            cookie.values("Language") = rbLan.SelectedItem.Value
            cookie.values.Expires = DateTime.Now.AddDays(7)
Response.AppendCookie(cookie)

        End If
0
 
LVL 4

Expert Comment

by:Steve Sirica
ID: 17980973
If the Request.Cookies("LoginSettings") Is Nothing shouldn't the Response.AppendCookie(cookie) line be Response.Cookies.add(cookie)?

 
0
 
LVL 7

Author Comment

by:Camillia
ID: 17981143

I dont know, should it be append or add?? does it make a diff??

0
 
LVL 4

Expert Comment

by:Steve Sirica
ID: 17981174
Not sure.  I've always understood it that you append to something that exists and add something that's new.  Using that logic, if Request.Cookies("LoginSettings") Is Nothing there's nothing to append too?
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

707 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