Cookie问题 [英] Problem with cookies
问题描述
这是我第一次尝试使用cookies,尽管阅读了一些
tutotials,但我真的很难让它正常工作。我的饼干
阅读代码在Master Page中。当我点击一个测试按钮(在aspx页面内的WEb
用户控件中)时,cookie值显示在Master
Page中,但是如果我转到另一个页面,没有显示任何价值...
我需要能够在整个网站上使用cookie的价值......我是什么?
做什么错误?
WebUser控件中的代码,这个代码点击按钮事件:
8< --------- ------------
HttpContext.Current.Response.Cookies [" TestValue"]。Value = mstrMyValue;
HttpContext.Current.Response.Cookies [" TestValue"]。Expires =
DateTime.Today.AddDays(365);
----- ----------------> 8
此代码在我母版页的OnPreRender中:
8< ---------------------
if(Request.Cookies [" TestValue"]! = null){
litCookieTest.Text = Response.Cookies [" TestValue"]。值;
}其他{
litCook ieTest.Text = Request.Cookies [" TestValue"]。Value;
}
----------------- ----> 8
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
推荐答案
Patxi,
如果在OnPreRender中放置断点事件处理程序是否一直调用
它不会一直调用。是因为缓存?
SA
Patxi < PA *** @ yahoo.com>在消息中写道
news:44 ********************* @ news.free.fr ...
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" <pa***@yahoo.com> wrote in message
news:44*********************@news.free.fr...
这是我第一次尝试使用cookies,尽管阅读了一些
tutotials,但我真的很难让它正常工作。我的cookie
阅读代码在Master Page中。当我点击一个测试按钮(在aspx页面内的WEb
用户控件中)时,cookie值显示在Master
Page中,但是如果我转到另一个页面,则不会显示任何值...
我需要能够在所有网站上使用cookie的价值......我做错了什么?
WebUser控件中的代码,这个按钮点击事件的代码:
8< ---------------------
HttpContext.Current。 Response.Cookies [" TestValue"]。Value = mstrMyValue;
HttpContext.Current.Response.Cookies [" TestValue"]。Expires =
DateTime.Today.AddDays(365);
---------------------> 8
这个代码在我母版页的OnPreRender中:
8< ---------------------
if(Request.Cookies [" TestValue"]!= null ){
litCookieTest.Text = Response.Cookies [" TestValue"]。Value;
} else {
litCookieTest.Text = Request.Cookies [" TestValue"]。Value;
}
------ ---------------> 8
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
mstrMyValue的值是多少?
-
HTH,
Kevin Spencer
Microsoft MVP
专业Numbskull
努力工作是一种药物,
没有安慰剂。
" MSDN" <平方********** @ hotmail.com>在消息中写道
新闻:eW ************** @ TK2MSFTNGP02.phx.gbl ...
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" <sq**********@hotmail.com> wrote in message
news:eW**************@TK2MSFTNGP02.phx.gbl...
Patxi,>
如果你在OnPreRender事件处理程序中放置一个断点,它会一直调用
它不会一直调用。是否由于缓存?
SA
Patxi < PA *** @ yahoo.com>在消息中写道
新闻:44 ********************* @ news.free.fr ...
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" <pa***@yahoo.com> wrote in message
news:44*********************@news.free.fr...
这是我第一次尝试使用cookies,尽管阅读了一些
tutotials,但我真的很难让它正常工作。我的cookie
阅读代码在Master Page中。当我点击一个测试按钮(在aspx页面内的WEb
用户控件中)时,cookie值显示在Master
Page中,但是如果我转到另一个页面,则不会显示任何值...
我需要能够在所有网站上使用cookie的价值......我做错了什么?
WebUser控件中的代码,这个按钮点击事件的代码:
8< ---------------------
HttpContext.Current。 Response.Cookies [" TestValue"]。Value = mstrMyValue;
HttpContext.Current.Response.Cookies [" TestValue"]。Expires =
DateTime.Today.AddDays(365);
---------------------> 8
这个代码在我母版页的OnPreRender中:
8< ---------------------
if(Request.Cookies [" TestValue"]!= null ){
litCookieTest.Text = Response.Cookies [" TestValue"]。Value;
} else {
litCookieTest.Text = Request.Cookies [" TestValue"]。Value;
}
------ ---------------> 8
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
Kevin,>
即使mstrMyValue =" SomeValue"它仍然不起作用
页面之间的Cookie值丢失。
谢谢
B
" Kevin Spencer" <柯*** @ DIESPAMMERSDIEtakempis.com>在消息中写道
news:uh ************* @ TK2MSFTNGP02.phx.gbl ...
Kevin,
Even if mstrMyValue = "SomeValue" it still does not work
the Cookie value is lost between pages.
Thanks
B
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:uh*************@TK2MSFTNGP02.phx.gbl...
mstrMyValue的值是多少?
-
HTH,
Kevin Spencer
微软MVP
专业Numbskull
努力工作是没有安慰剂的药物。
MSDN <平方********** @ hotmail.com>在消息中写道
新闻:eW ************** @ TK2MSFTNGP02.phx.gbl ...
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" <sq**********@hotmail.com> wrote in message
news:eW**************@TK2MSFTNGP02.phx.gbl...
Patxi,
>如果你在OnPreRender事件处理程序中放置一个断点,它会一直调用
它不会一直被调用。是否由于缓存?
SA
Patxi < PA *** @ yahoo.com>在消息中写道
新闻:44 ********************* @ news.free.fr ...
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" <pa***@yahoo.com> wrote in message
news:44*********************@news.free.fr...
这是我第一次尝试使用cookies,尽管阅读了一些
tutotials,但我真的很难让它正常工作。我的cookie
阅读代码在Master Page中。当我点击一个测试按钮(在aspx页面内的WEb
用户控件中)时,cookie值显示在Master
Page中,但是如果我转到另一个页面,则不会显示任何值...
我需要能够在所有网站上使用cookie的价值......我做错了什么?
WebUser控件中的代码,这个按钮点击事件的代码:
8< ---------------------
HttpContext.Current。 Response.Cookies [" TestValue"]。Value = mstrMyValue;
HttpContext.Current.Response.Cookies [" TestValue"]。Expires =
DateTime.Today.AddDays(365);
---------------------> 8
这个代码在我母版页的OnPreRender中:
8< ---------------------
if(Request.Cookies [" TestValue"]!= null ){
litCookieTest.Text = Response.Cookies [" TestValue"]。Value;
} else {
litCookieTest.Text = Request.Cookies [" TestValue"]。Value;
}
------ ---------------> 8
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
这篇关于Cookie问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!