Solved

Cookie returning null error

Posted on 2006-11-20
4
227 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

943 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

10 Experts available now in Live!

Get 1:1 Help Now