Solved

Cookie returning null error

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

832 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