Problem with cookies

P

Patxi

This is the first time I try to use cookies, and despite of reading some
tutotials, I'm have real trouble to make it work correctly. My cookie
reading code is in Master Page. When I click on a test button (in a WEb
User Control inside the aspx page), cookie value is displayed in Master
Page but if I go to another page, no value is displayed...

I need to be able tu use cookie's value across all the site... What am I
doing wrong ?

Code in WebUser control, this code on a button click event:

8<---------------------

HttpContext.Current.Response.Cookies["TestValue"].Value = mstrMyValue;
HttpContext.Current.Response.Cookies["TestValue"].Expires =
DateTime.Today.AddDays(365);

--------------------->8

And this code in OnPreRender of my Master page:

8<---------------------

if (Request.Cookies["TestValue"] != null){
litCookieTest.Text = Response.Cookies["TestValue"].Value;
}else{
litCookieTest.Text = Request.Cookies["TestValue"].Value;
}
--------------------->8
 
M

MSDN

Patxi,

If you put a breakpoint in the OnPreRender event handler does it get called
all the time
It is not called all the time. Is it due to caching??

SA
 
K

Kevin Spencer

What is the value of mstrMyValue?

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

MSDN said:
Patxi,

If you put a breakpoint in the OnPreRender event handler does it get
called all the time
It is not called all the time. Is it due to caching??

SA

Patxi said:
This is the first time I try to use cookies, and despite of reading some
tutotials, I'm have real trouble to make it work correctly. My cookie
reading code is in Master Page. When I click on a test button (in a WEb
User Control inside the aspx page), cookie value is displayed in Master
Page but if I go to another page, no value is displayed...

I need to be able tu use cookie's value across all the site... What am I
doing wrong ?

Code in WebUser control, this code on a button click event:

8<---------------------

HttpContext.Current.Response.Cookies["TestValue"].Value = mstrMyValue;
HttpContext.Current.Response.Cookies["TestValue"].Expires =
DateTime.Today.AddDays(365);

--------------------->8

And this code in OnPreRender of my Master page:

8<---------------------

if (Request.Cookies["TestValue"] != null){
litCookieTest.Text = Response.Cookies["TestValue"].Value;
}else{
litCookieTest.Text = Request.Cookies["TestValue"].Value;
}
--------------------->8
 
D

Dumbell

Kevin,

Even if mstrMyValue = "SomeValue" it still does not work
the Cookie value is lost between pages.

Thanks

B

Kevin Spencer said:
What is the value of mstrMyValue?

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

MSDN said:
Patxi,

If you put a breakpoint in the OnPreRender event handler does it get
called all the time
It is not called all the time. Is it due to caching??

SA

Patxi said:
This is the first time I try to use cookies, and despite of reading some
tutotials, I'm have real trouble to make it work correctly. My cookie
reading code is in Master Page. When I click on a test button (in a WEb
User Control inside the aspx page), cookie value is displayed in Master
Page but if I go to another page, no value is displayed...

I need to be able tu use cookie's value across all the site... What am I
doing wrong ?

Code in WebUser control, this code on a button click event:

8<---------------------

HttpContext.Current.Response.Cookies["TestValue"].Value = mstrMyValue;
HttpContext.Current.Response.Cookies["TestValue"].Expires =
DateTime.Today.AddDays(365);

--------------------->8

And this code in OnPreRender of my Master page:

8<---------------------

if (Request.Cookies["TestValue"] != null){
litCookieTest.Text = Response.Cookies["TestValue"].Value;
}else{
litCookieTest.Text = Request.Cookies["TestValue"].Value;
}
--------------------->8
 
P

Patxi

I have no chache settings...
Patxi,

If you put a breakpoint in the OnPreRender event handler does it get called
all the time
It is not called all the time. Is it due to caching??

SA

Patxi said:
This is the first time I try to use cookies, and despite of reading some
tutotials, I'm have real trouble to make it work correctly. My cookie
reading code is in Master Page. When I click on a test button (in a WEb
User Control inside the aspx page), cookie value is displayed in Master
Page but if I go to another page, no value is displayed...

I need to be able tu use cookie's value across all the site... What am I
doing wrong ?

Code in WebUser control, this code on a button click event:

8<---------------------

HttpContext.Current.Response.Cookies["TestValue"].Value = mstrMyValue;
HttpContext.Current.Response.Cookies["TestValue"].Expires =
DateTime.Today.AddDays(365);

--------------------->8

And this code in OnPreRender of my Master page:

8<---------------------

if (Request.Cookies["TestValue"] != null){
litCookieTest.Text = Response.Cookies["TestValue"].Value;
}else{
litCookieTest.Text = Request.Cookies["TestValue"].Value;
}
--------------------->8
 
P

Patxi

My main problem is that I set cookie's value in Default.aspx, and when I
refresh the page or visit another page, I'm unable to retreive
cookie's value...

I think that cookie is only saved between pages refresh instead of
having a 'site' cookie...

I really try to applicate tutorials, but I think I'm missing something...
Kevin,

Even if mstrMyValue = "SomeValue" it still does not work
the Cookie value is lost between pages.

Thanks

B

Kevin Spencer said:
What is the value of mstrMyValue?

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

MSDN said:
Patxi,

If you put a breakpoint in the OnPreRender event handler does it get
called all the time
It is not called all the time. Is it due to caching??

SA

This is the first time I try to use cookies, and despite of reading some
tutotials, I'm have real trouble to make it work correctly. My cookie
reading code is in Master Page. When I click on a test button (in a WEb
User Control inside the aspx page), cookie value is displayed in Master
Page but if I go to another page, no value is displayed...

I need to be able tu use cookie's value across all the site... What am I
doing wrong ?

Code in WebUser control, this code on a button click event:

8<---------------------

HttpContext.Current.Response.Cookies["TestValue"].Value = mstrMyValue;
HttpContext.Current.Response.Cookies["TestValue"].Expires =
DateTime.Today.AddDays(365);

--------------------->8

And this code in OnPreRender of my Master page:

8<---------------------

if (Request.Cookies["TestValue"] != null){
litCookieTest.Text = Response.Cookies["TestValue"].Value;
}else{
litCookieTest.Text = Request.Cookies["TestValue"].Value;
}
--------------------->8
 
M

MSDN

This is very strange I am having the same problem you are having using your
example.
it seems that the cookie is saved for a specific page and not the entire
website.
I suspected that may be it has to do with ASP.NET 2.0 and VS 2005 and the
WebServer with PORT NUMBER etc...
So I moved the sample I have to a web site and the same thing is happening.
The cookie does not have to persist.
Still looking for an answer.

SA

Patxi said:
I have no chache settings...
Patxi,

If you put a breakpoint in the OnPreRender event handler does it get
called all the time
It is not called all the time. Is it due to caching??

SA

Patxi said:
This is the first time I try to use cookies, and despite of reading some
tutotials, I'm have real trouble to make it work correctly. My cookie
reading code is in Master Page. When I click on a test button (in a WEb
User Control inside the aspx page), cookie value is displayed in Master
Page but if I go to another page, no value is displayed...

I need to be able tu use cookie's value across all the site... What am I
doing wrong ?

Code in WebUser control, this code on a button click event:

8<---------------------

HttpContext.Current.Response.Cookies["TestValue"].Value = mstrMyValue;
HttpContext.Current.Response.Cookies["TestValue"].Expires =
DateTime.Today.AddDays(365);

--------------------->8

And this code in OnPreRender of my Master page:

8<---------------------

if (Request.Cookies["TestValue"] != null){
litCookieTest.Text = Response.Cookies["TestValue"].Value;
}else{
litCookieTest.Text = Request.Cookies["TestValue"].Value;
}
--------------------->8
 
P

Patxi

For the record, I'm using an IIS virtual directory, running IIS 5.0...
This is very strange I am having the same problem you are having using your
example.
it seems that the cookie is saved for a specific page and not the entire
website.
I suspected that may be it has to do with ASP.NET 2.0 and VS 2005 and the
WebServer with PORT NUMBER etc...
So I moved the sample I have to a web site and the same thing is happening.
The cookie does not have to persist.
Still looking for an answer.

SA

Patxi said:
I have no chache settings...
Patxi,

If you put a breakpoint in the OnPreRender event handler does it get
called all the time
It is not called all the time. Is it due to caching??

SA

This is the first time I try to use cookies, and despite of reading some
tutotials, I'm have real trouble to make it work correctly. My cookie
reading code is in Master Page. When I click on a test button (in a WEb
User Control inside the aspx page), cookie value is displayed in Master
Page but if I go to another page, no value is displayed...

I need to be able tu use cookie's value across all the site... What am I
doing wrong ?

Code in WebUser control, this code on a button click event:

8<---------------------

HttpContext.Current.Response.Cookies["TestValue"].Value = mstrMyValue;
HttpContext.Current.Response.Cookies["TestValue"].Expires =
DateTime.Today.AddDays(365);

--------------------->8

And this code in OnPreRender of my Master page:

8<---------------------

if (Request.Cookies["TestValue"] != null){
litCookieTest.Text = Response.Cookies["TestValue"].Value;
}else{
litCookieTest.Text = Request.Cookies["TestValue"].Value;
}
--------------------->8
 
M

MSDN

Patxi,

Have you tired this without master page?
I am using IIS 5.1, Win XP Pro

SA

Patxi said:
For the record, I'm using an IIS virtual directory, running IIS 5.0...
This is very strange I am having the same problem you are having using
your example.
it seems that the cookie is saved for a specific page and not the entire
website.
I suspected that may be it has to do with ASP.NET 2.0 and VS 2005 and the
WebServer with PORT NUMBER etc...
So I moved the sample I have to a web site and the same thing is
happening.
The cookie does not have to persist.
Still looking for an answer.

SA

Patxi said:
I have no chache settings...

MSDN wrote:
Patxi,

If you put a breakpoint in the OnPreRender event handler does it get
called all the time
It is not called all the time. Is it due to caching??

SA

This is the first time I try to use cookies, and despite of reading
some tutotials, I'm have real trouble to make it work correctly. My
cookie reading code is in Master Page. When I click on a test button
(in a WEb User Control inside the aspx page), cookie value is
displayed in Master Page but if I go to another page, no value is
displayed...

I need to be able tu use cookie's value across all the site... What am
I doing wrong ?

Code in WebUser control, this code on a button click event:

8<---------------------

HttpContext.Current.Response.Cookies["TestValue"].Value = mstrMyValue;
HttpContext.Current.Response.Cookies["TestValue"].Expires =
DateTime.Today.AddDays(365);

--------------------->8

And this code in OnPreRender of my Master page:

8<---------------------

if (Request.Cookies["TestValue"] != null){
litCookieTest.Text = Response.Cookies["TestValue"].Value;
}else{
litCookieTest.Text = Request.Cookies["TestValue"].Value;
}
--------------------->8
 
P

Patxi

I stopped trying it, I'm trying Profile system... But I have a big
problem, since it works against SQL and I'm developping a 3 tier
application, so I would like to use my BLL or a single XML file to store
profiles, but I'm unable to find an implemention in XML...

I'm studying
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASPNETProvMod_Prt5.asp
but I can't find a more realistic example of xml driven
ProfileProvider... Can you point me to a more practical site ?

Thanks
Patxi,

Have you tired this without master page?
I am using IIS 5.1, Win XP Pro

SA

Patxi said:
For the record, I'm using an IIS virtual directory, running IIS 5.0...
This is very strange I am having the same problem you are having using
your example.
it seems that the cookie is saved for a specific page and not the entire
website.
I suspected that may be it has to do with ASP.NET 2.0 and VS 2005 and the
WebServer with PORT NUMBER etc...
So I moved the sample I have to a web site and the same thing is
happening.
The cookie does not have to persist.
Still looking for an answer.

SA

I have no chache settings...

MSDN wrote:
Patxi,

If you put a breakpoint in the OnPreRender event handler does it get
called all the time
It is not called all the time. Is it due to caching??

SA

This is the first time I try to use cookies, and despite of reading
some tutotials, I'm have real trouble to make it work correctly. My
cookie reading code is in Master Page. When I click on a test button
(in a WEb User Control inside the aspx page), cookie value is
displayed in Master Page but if I go to another page, no value is
displayed...

I need to be able tu use cookie's value across all the site... What am
I doing wrong ?

Code in WebUser control, this code on a button click event:

8<---------------------

HttpContext.Current.Response.Cookies["TestValue"].Value = mstrMyValue;
HttpContext.Current.Response.Cookies["TestValue"].Expires =
DateTime.Today.AddDays(365);

--------------------->8

And this code in OnPreRender of my Master page:

8<---------------------

if (Request.Cookies["TestValue"] != null){
litCookieTest.Text = Response.Cookies["TestValue"].Value;
}else{
litCookieTest.Text = Request.Cookies["TestValue"].Value;
}
--------------------->8
 
P

Patxi

Incredible !!!

I'm testing with Profile and I'm having the same problem...

I create a Web User control (ProfileViewer.ascx) with a label, and this
code in the Page_Load event:

Label1.Text = Profile.FirstName;

I have another Web User control (ProfileSetCtrl.ascx) with a button and
this code on button's click event:

Profile.FirstName = mstrMyValue; (mstrMyValue is the path of jpg file)

In my Default.aspx file, I scan for jpgs in a directory and load one
ProfileSetCtrl.ascx per jpg, passing the jpg file path...

I click on button displaying 1.jpg, ProfileViewer.ascx shows the default
value configured in Web.config displayed...

I click on button displaying 3.jpg, and ProfileViewer.ascx shows 1.jpg...

What am I missing ?

Thanks
Patxi,

Have you tired this without master page?
I am using IIS 5.1, Win XP Pro

SA

Patxi said:
For the record, I'm using an IIS virtual directory, running IIS 5.0...
This is very strange I am having the same problem you are having using
your example.
it seems that the cookie is saved for a specific page and not the entire
website.
I suspected that may be it has to do with ASP.NET 2.0 and VS 2005 and the
WebServer with PORT NUMBER etc...
So I moved the sample I have to a web site and the same thing is
happening.
The cookie does not have to persist.
Still looking for an answer.

SA

I have no chache settings...

MSDN wrote:
Patxi,

If you put a breakpoint in the OnPreRender event handler does it get
called all the time
It is not called all the time. Is it due to caching??

SA

This is the first time I try to use cookies, and despite of reading
some tutotials, I'm have real trouble to make it work correctly. My
cookie reading code is in Master Page. When I click on a test button
(in a WEb User Control inside the aspx page), cookie value is
displayed in Master Page but if I go to another page, no value is
displayed...

I need to be able tu use cookie's value across all the site... What am
I doing wrong ?

Code in WebUser control, this code on a button click event:

8<---------------------

HttpContext.Current.Response.Cookies["TestValue"].Value = mstrMyValue;
HttpContext.Current.Response.Cookies["TestValue"].Expires =
DateTime.Today.AddDays(365);

--------------------->8

And this code in OnPreRender of my Master page:

8<---------------------

if (Request.Cookies["TestValue"] != null){
litCookieTest.Text = Response.Cookies["TestValue"].Value;
}else{
litCookieTest.Text = Request.Cookies["TestValue"].Value;
}
--------------------->8
 
M

MSDN

This is extremely frustration for me also I have no Idea
It seems no one else is reading this at all

May be bring this question back to the top of the list and lets start over
again.

Sorry...

SA


Patxi said:
Incredible !!!

I'm testing with Profile and I'm having the same problem...

I create a Web User control (ProfileViewer.ascx) with a label, and this
code in the Page_Load event:

Label1.Text = Profile.FirstName;

I have another Web User control (ProfileSetCtrl.ascx) with a button and
this code on button's click event:

Profile.FirstName = mstrMyValue; (mstrMyValue is the path of jpg file)

In my Default.aspx file, I scan for jpgs in a directory and load one
ProfileSetCtrl.ascx per jpg, passing the jpg file path...

I click on button displaying 1.jpg, ProfileViewer.ascx shows the default
value configured in Web.config displayed...

I click on button displaying 3.jpg, and ProfileViewer.ascx shows 1.jpg...

What am I missing ?

Thanks
Patxi,

Have you tired this without master page?
I am using IIS 5.1, Win XP Pro

SA

Patxi said:
For the record, I'm using an IIS virtual directory, running IIS 5.0...

MSDN wrote:
This is very strange I am having the same problem you are having using
your example.
it seems that the cookie is saved for a specific page and not the
entire website.
I suspected that may be it has to do with ASP.NET 2.0 and VS 2005 and
the WebServer with PORT NUMBER etc...
So I moved the sample I have to a web site and the same thing is
happening.
The cookie does not have to persist.
Still looking for an answer.

SA

I have no chache settings...

MSDN wrote:
Patxi,

If you put a breakpoint in the OnPreRender event handler does it get
called all the time
It is not called all the time. Is it due to caching??

SA

This is the first time I try to use cookies, and despite of reading
some tutotials, I'm have real trouble to make it work correctly. My
cookie reading code is in Master Page. When I click on a test
button (in a WEb User Control inside the aspx page), cookie value is
displayed in Master Page but if I go to another page, no value is
displayed...

I need to be able tu use cookie's value across all the site... What
am I doing wrong ?

Code in WebUser control, this code on a button click event:

8<---------------------

HttpContext.Current.Response.Cookies["TestValue"].Value =
mstrMyValue;
HttpContext.Current.Response.Cookies["TestValue"].Expires =
DateTime.Today.AddDays(365);

--------------------->8

And this code in OnPreRender of my Master page:

8<---------------------

if (Request.Cookies["TestValue"] != null){
litCookieTest.Text = Response.Cookies["TestValue"].Value;
}else{
litCookieTest.Text = Request.Cookies["TestValue"].Value;
}
--------------------->8
 
P

Patxi

I solved it adding this:

this.Context.Response.Redirect(this.Context.Request.Url.ToString());

after setting profile's value...
This is extremely frustration for me also I have no Idea
It seems no one else is reading this at all

May be bring this question back to the top of the list and lets start over
again.

Sorry...

SA


Patxi said:
Incredible !!!

I'm testing with Profile and I'm having the same problem...

I create a Web User control (ProfileViewer.ascx) with a label, and this
code in the Page_Load event:

Label1.Text = Profile.FirstName;

I have another Web User control (ProfileSetCtrl.ascx) with a button and
this code on button's click event:

Profile.FirstName = mstrMyValue; (mstrMyValue is the path of jpg file)

In my Default.aspx file, I scan for jpgs in a directory and load one
ProfileSetCtrl.ascx per jpg, passing the jpg file path...

I click on button displaying 1.jpg, ProfileViewer.ascx shows the default
value configured in Web.config displayed...

I click on button displaying 3.jpg, and ProfileViewer.ascx shows 1.jpg...

What am I missing ?

Thanks
Patxi,

Have you tired this without master page?
I am using IIS 5.1, Win XP Pro

SA

For the record, I'm using an IIS virtual directory, running IIS 5.0...

MSDN wrote:
This is very strange I am having the same problem you are having using
your example.
it seems that the cookie is saved for a specific page and not the
entire website.
I suspected that may be it has to do with ASP.NET 2.0 and VS 2005 and
the WebServer with PORT NUMBER etc...
So I moved the sample I have to a web site and the same thing is
happening.
The cookie does not have to persist.
Still looking for an answer.

SA

I have no chache settings...

MSDN wrote:
Patxi,

If you put a breakpoint in the OnPreRender event handler does it get
called all the time
It is not called all the time. Is it due to caching??

SA

This is the first time I try to use cookies, and despite of reading
some tutotials, I'm have real trouble to make it work correctly. My
cookie reading code is in Master Page. When I click on a test
button (in a WEb User Control inside the aspx page), cookie value is
displayed in Master Page but if I go to another page, no value is
displayed...

I need to be able tu use cookie's value across all the site... What
am I doing wrong ?

Code in WebUser control, this code on a button click event:

8<---------------------

HttpContext.Current.Response.Cookies["TestValue"].Value =
mstrMyValue;
HttpContext.Current.Response.Cookies["TestValue"].Expires =
DateTime.Today.AddDays(365);

--------------------->8

And this code in OnPreRender of my Master page:

8<---------------------

if (Request.Cookies["TestValue"] != null){
litCookieTest.Text = Response.Cookies["TestValue"].Value;
}else{
litCookieTest.Text = Request.Cookies["TestValue"].Value;
}
--------------------->8
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top