473,246 Members | 1,304 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,246 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 3553
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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.