473,396 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Changing Response.Cookie from Instance to Shared (Static) Problem

When I write inline code on a aspx page using Page.Response.Cookies() to read a cookie, everything works fine, as in the following code.

Dim x As Object = Request.Cookies("thing")
If x Is Nothing Then
CurrentValue.Text = "No Cookie Defined"
Else
CurrentValue.Text = Request.Cookies("thing").Value
End If

However, I wanted to move the code to a shared method so I do not have access to the instance Page class any more so I used the shared method from System.Web.HttpContext.Current.Request.Cookies(). This, however, did not yeald the same results as the oringonal code (Aka: did not work). See the following code

Private Shared Function ReadCookieOr(ByVal CookieName As String, ByVal NothingReturnValue As String) As String
Dim x As Object = System.Web.HttpContext.Current.Response.Cookies(Co okieName)
If x Is Nothing Then
Return NothingReturnValue
Else
Return System.Web.HttpContext.Current.Request.Cookies(Coo kieName).Value
End If
End Function

Here are my issues:
1. How do I determine if the Shared(or static) Cookies method contains a value, like I do in the inline code (using: If x Is Nothing)
2. If I do need assign a reference of this class to an object, how do I cast that object back to origonal class (I guess in VB.net it would use ctype...)
3. In the above example, why does System.Web.HttpContext.Current.Request.Cookies(Coo kieName).Value never return a value that was set earlier (but the instance method does)

Thank you for your help

Earl
Nov 18 '05 #1
1 3561
Cookies is a property of the Request or Response object, not a method.

1) I don't understand what you mean. 'If x Is Nothing', will work in either
case
2) You should not declare x as Object, it should be an HttpCookie. Always
use 'Options Strict On'.
3) Because you set 'x' to a cookie from the Response, not Request. Where as
in the inline code, you always use Request.

"Earl Teigrob" <Ea*********@discussions.microsoft.com> wrote in message
news:6D**********************************@microsof t.com...
When I write inline code on a aspx page using Page.Response.Cookies() to read a cookie, everything works fine, as in the following code.
Dim x As Object = Request.Cookies("thing")
If x Is Nothing Then
CurrentValue.Text = "No Cookie Defined"
Else
CurrentValue.Text = Request.Cookies("thing").Value
End If

However, I wanted to move the code to a shared method so I do not have access to the instance Page class any more so I used the shared method from
System.Web.HttpContext.Current.Request.Cookies(). This, however, did not
yeald the same results as the oringonal code (Aka: did not work). See the
following code
Private Shared Function ReadCookieOr(ByVal CookieName As String, ByVal NothingReturnValue As String) As String Dim x As Object = System.Web.HttpContext.Current.Response.Cookies(Co okieName) If x Is Nothing Then
Return NothingReturnValue
Else
Return System.Web.HttpContext.Current.Request.Cookies(Coo kieName).Value End If
End Function

Here are my issues:
1. How do I determine if the Shared(or static) Cookies method contains a value, like I do in the inline code (using: If x Is Nothing) 2. If I do need assign a reference of this class to an object, how do I cast that object back to origonal class (I guess in VB.net it would use
ctype...) 3. In the above example, why does System.Web.HttpContext.Current.Request.Cookies(Coo kieName).Value never
return a value that was set earlier (but the instance method does)
Thank you for your help

Earl

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phil Powell | last post by:
I am having trouble retrieving URLs using curl for PHP whereby the URL requires a cookie to produce proper data. I wrote a wrapper class called Timer that will time the execution/download of a...
3
by: M Wells | last post by:
Hi All, Just wondering how you go about changing the value of a session cookie via javascript? I have a PHP page that sets a session cookie when it first loads. I'd like to be able to change...
6
by: Mark | last post by:
Hi... I've come across some weird bug with Response.Cookies. Or maybe it will be called "by design" but for the life of me I can't figure out what purpose it would serve. If you're setting a...
0
by: tshad | last post by:
I can add a cookie fine, but I can't seem to figure out how to change the value of a cookie and save it back. My code looks like: if (passwordSaveCookie.checked) then If...
3
by: Adam | last post by:
We have a web site that uses .vb for the web pages and .cs for a class module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does work with .NET 1.1. When trying to access a page...
11
by: syssyx | last post by:
I have a "CurrentUser" object in session that I want to access from each page of a vb.net website. I can successfully access everything if I include the following at the start of each pageload: ...
5
by: Dinsdale | last post by:
I was discussing class architecture with one of the senior developers at my new job and him and I have a similar idea on how to work with data access and class libraries. That said, our...
9
by: David | last post by:
With a non-server app there is one instance of the program running and one user 'using' it at a time. With this scenario I'm pretty comfortable with variable scope and lifetime. With a server app...
4
by: Dave | last post by:
I have a global.asax file with Application_Start defined and create some static data there and in another module used in the asp.net application and I realize that static data is shared amongst...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.