468,531 Members | 1,721 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,531 developers. It's quick & easy.

Give Request.Cookies and Response.Cookies is there any reason to use another method to use cookies?

Given Request.Cookies and Response.Cookies in asp.net is there any reason to
ever use javascript or any other method to use cookies?

Thanks
Sep 18 '08 #1
10 1424
eg :if you want to save the layout of the ajax page.
"_Who" <Ca**********@roadrunner.com写入消息
news:ey*************@TK2MSFTNGP02.phx.gbl...
Given Request.Cookies and Response.Cookies in asp.net is there any reason
to ever use javascript or any other method to use cookies?

Thanks

Sep 18 '08 #2
For example if you have to set them client side... Not sure what is the goal
of this question though ? IMO in most cases you'll use server side code if
what you want is a confirmation that what you does is quite standard...

--
Patrice

"_Who" <Ca**********@roadrunner.coma 閏rit dans le message de groupe de
discussion : ey*************@TK2MSFTNGP02.phx.gbl...
Given Request.Cookies and Response.Cookies in asp.net is there any reason
to ever use javascript or any other method to use cookies?

Thanks

Sep 18 '08 #3
There is much JavaScript cookie code on the Internet and in books, that
shows how to write, read, and take apart what is read.
I have some saved. I was wondering if there is any reason for me to save
that.

Also, I work alone so it would be valuable to hear that using
Request.Cookies and Response.Cookies is a good approach not withstanding all
the code that uses document.cookie.

It's confusing. For example your statement: "For example if you have to set
them client side... "
Is there some reason to do that?

In fact, I'm looking at a 75-line code that is used to display the number of
visits by the person to the site. It uses document.cookie and JavaScript. Is
that the way you'd do it?

Thanks for helping
"Patrice" <http://www.chez.com/scribe/wrote in message
news:0A**********************************@microsof t.com...
For example if you have to set them client side... Not sure what is the
goal of this question though ? IMO in most cases you'll use server side
code if what you want is a confirmation that what you does is quite
standard...

--
Patrice

"_Who" <Ca**********@roadrunner.coma 閏rit dans le message de groupe de
discussion : ey*************@TK2MSFTNGP02.phx.gbl...
>Given Request.Cookies and Response.Cookies in asp.net is there any reason
to ever use javascript or any other method to use cookies?

Thanks


Sep 18 '08 #4

<ch*****@126.comwrote in message
news:59**********************************@microsof t.com...
eg :if you want to save the layout of the ajax page.
I don't think I'm there yet. I mean I haven't gotten to ajax yet.

Thanks

>

"_Who" <Ca**********@roadrunner.com写入消息
news:ey*************@TK2MSFTNGP02.phx.gbl...
>Given Request.Cookies and Response.Cookies in asp.net is there any reason
to ever use javascript or any other method to use cookies?

Thanks


Sep 18 '08 #5
IMO don't save something you find easily on the web. Knowing you can is
enough and you'll have no problem to find this again when needed...

You have likely more than this cookie to produce an approximate number of
current users on your site and no I wouldn't do this way (you have a cookie
though for your ASP.NET session).

I remember to have done this at least one time (setting the cookie client
side) but I don't remember what was the purpose.

I would do things the other way round. Instead of asking why you would do
something in a particular way, tell rather what you are trying to do and
someone will likely give - if not the mythical "best way" - at least a
possible logical way to do that...

Do you want to display on your page an approximate number of users currently
visiting the site ?

--
Patrice

"_Who" <Ca**********@roadrunner.coma 閏rit dans le message de groupe de
discussion : Of**************@TK2MSFTNGP06.phx.gbl...
There is much JavaScript cookie code on the Internet and in books, that
shows how to write, read, and take apart what is read.
I have some saved. I was wondering if there is any reason for me to save
that.

Also, I work alone so it would be valuable to hear that using
Request.Cookies and Response.Cookies is a good approach not withstanding
all the code that uses document.cookie.

It's confusing. For example your statement: "For example if you have to
set them client side... "
Is there some reason to do that?

In fact, I'm looking at a 75-line code that is used to display the number
of visits by the person to the site. It uses document.cookie and
JavaScript. Is that the way you'd do it?

Thanks for helping


Sep 18 '08 #6
The answer your last question is yes.

But I find mostly cookie code on the internet uses JavaScript and from your
reply I now know that with ASP.NET that is not the way to go. For that I
thank you.
"Patrice" <http://www.chez.com/scribe/wrote in message
news:F5**********************************@microsof t.com...
IMO don't save something you find easily on the web. Knowing you can is
enough and you'll have no problem to find this again when needed...

You have likely more than this cookie to produce an approximate number of
current users on your site and no I wouldn't do this way (you have a
cookie though for your ASP.NET session).

I remember to have done this at least one time (setting the cookie client
side) but I don't remember what was the purpose.

I would do things the other way round. Instead of asking why you would do
something in a particular way, tell rather what you are trying to do and
someone will likely give - if not the mythical "best way" - at least a
possible logical way to do that...

Do you want to display on your page an approximate number of users
currently visiting the site ?

--
Patrice

"_Who" <Ca**********@roadrunner.coma 閏rit dans le message de groupe de
discussion : Of**************@TK2MSFTNGP06.phx.gbl...
>There is much JavaScript cookie code on the Internet and in books, that
shows how to write, read, and take apart what is read.
I have some saved. I was wondering if there is any reason for me to save
that.

Also, I work alone so it would be valuable to hear that using
Request.Cookies and Response.Cookies is a good approach not withstanding
all the code that uses document.cookie.

It's confusing. For example your statement: "For example if you have to
set them client side... "
Is there some reason to do that?

In fact, I'm looking at a 75-line code that is used to display the number
of visits by the person to the site. It uses document.cookie and
JavaScript. Is that the way you'd do it?

Thanks for helping



Sep 18 '08 #7
"_Who" <Ca**********@roadrunner.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
The answer your last question is yes.

But I find mostly cookie code on the internet uses JavaScript and from
your reply I now know that with ASP.NET that is not the way to go. For
that I thank you.
I'm not sure what its you are seeing. It is possible for cookies to be used
by both client and server. You use Javascript clientside to read and set
cookie info, you use Response.Cookies to read cookies server side and
Resquest.Cookies to set them. Personally I rarely do the clientside thing
its usually server side.

--
Anthony Jones - MVP ASP/ASP.NET

Sep 18 '08 #8
A basic approach is to use the session start and end event (see
global.asax). Increase an application variable when a session starts and
decrease the application variable when the session ends.

That said the end event of a session doesn't happen in some cases (when
using the SQL Server provider) or is/was not known to be terribly reliable
so my personal approach would be :
- to keep track in an application variable of each session I heard about
including a timestamp
- counting recently used session (whatever criteria you want as you have a
timestamp) gives the number of users
- you can remove old sessions records from the list and you don't care about
session events happening or not

In all cases this is just indicative as http is stateless and you don't know
immediately when a user closes his browser. Some are doing a server side
call to close the session from a client side event but I never found it was
worth the trouble to go against http nature.

You should find lot of resources about this on Google (especially #1 and #3,
not sure about #2). In all cases, isolete this code so that you'll be able
to change the method you are suing at will without changing anyhting in the
rest of your code.

--
Patrice

"_Who" <Ca**********@roadrunner.coma 閏rit dans le message de groupe de
discussion : #K**************@TK2MSFTNGP04.phx.gbl...
The answer your last question is yes.

But I find mostly cookie code on the internet uses JavaScript and from
your reply I now know that with ASP.NET that is not the way to go. For
that I thank you.
"Patrice" <http://www.chez.com/scribe/wrote in message
news:F5**********************************@microsof t.com...
>IMO don't save something you find easily on the web. Knowing you can is
enough and you'll have no problem to find this again when needed...

You have likely more than this cookie to produce an approximate number of
current users on your site and no I wouldn't do this way (you have a
cookie though for your ASP.NET session).

I remember to have done this at least one time (setting the cookie client
side) but I don't remember what was the purpose.

I would do things the other way round. Instead of asking why you would do
something in a particular way, tell rather what you are trying to do and
someone will likely give - if not the mythical "best way" - at least a
possible logical way to do that...

Do you want to display on your page an approximate number of users
currently visiting the site ?

--
Patrice

"_Who" <Ca**********@roadrunner.coma 閏rit dans le message de groupe de
discussion : Of**************@TK2MSFTNGP06.phx.gbl...
>>There is much JavaScript cookie code on the Internet and in books, that
shows how to write, read, and take apart what is read.
I have some saved. I was wondering if there is any reason for me to save
that.

Also, I work alone so it would be valuable to hear that using
Request.Cookies and Response.Cookies is a good approach not withstanding
all the code that uses document.cookie.

It's confusing. For example your statement: "For example if you have to
set them client side... "
Is there some reason to do that?

In fact, I'm looking at a 75-line code that is used to display the
number of visits by the person to the site. It uses document.cookie and
JavaScript. Is that the way you'd do it?

Thanks for helping



Sep 18 '08 #9
I'm probably finding code for users not doing ASP.NET

Thanks

"Anthony Jones" <An***********@yadayadayada.comwrote in message
news:uj**************@TK2MSFTNGP03.phx.gbl...
"_Who" <Ca**********@roadrunner.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>The answer your last question is yes.

But I find mostly cookie code on the internet uses JavaScript and from
your reply I now know that with ASP.NET that is not the way to go. For
that I thank you.

I'm not sure what its you are seeing. It is possible for cookies to be
used by both client and server. You use Javascript clientside to read and
set cookie info, you use Response.Cookies to read cookies server side and
Resquest.Cookies to set them. Personally I rarely do the clientside
thing its usually server side.

--
Anthony Jones - MVP ASP/ASP.NET

Sep 18 '08 #10
Debugging once I noticed that the session end event was not raised.

Thanks for the info below.

"Patrice" <http://www.chez.com/scribe/wrote in message
news:7F**********************************@microsof t.com...
>A basic approach is to use the session start and end event (see
global.asax). Increase an application variable when a session starts and
decrease the application variable when the session ends.

That said the end event of a session doesn't happen in some cases (when
using the SQL Server provider) or is/was not known to be terribly reliable
so my personal approach would be :
- to keep track in an application variable of each session I heard about
including a timestamp
- counting recently used session (whatever criteria you want as you have a
timestamp) gives the number of users
- you can remove old sessions records from the list and you don't care
about session events happening or not

In all cases this is just indicative as http is stateless and you don't
know immediately when a user closes his browser. Some are doing a server
side call to close the session from a client side event but I never found
it was worth the trouble to go against http nature.

You should find lot of resources about this on Google (especially #1 and
#3, not sure about #2). In all cases, isolete this code so that you'll be
able to change the method you are suing at will without changing anyhting
in the rest of your code.

--
Patrice

"_Who" <Ca**********@roadrunner.coma 閏rit dans le message de groupe de
discussion : #K**************@TK2MSFTNGP04.phx.gbl...
>The answer your last question is yes.

But I find mostly cookie code on the internet uses JavaScript and from
your reply I now know that with ASP.NET that is not the way to go. For
that I thank you.
"Patrice" <http://www.chez.com/scribe/wrote in message
news:F5**********************************@microso ft.com...
>>IMO don't save something you find easily on the web. Knowing you can is
enough and you'll have no problem to find this again when needed...

You have likely more than this cookie to produce an approximate number
of current users on your site and no I wouldn't do this way (you have a
cookie though for your ASP.NET session).

I remember to have done this at least one time (setting the cookie
client side) but I don't remember what was the purpose.

I would do things the other way round. Instead of asking why you would
do something in a particular way, tell rather what you are trying to do
and someone will likely give - if not the mythical "best way" - at least
a possible logical way to do that...

Do you want to display on your page an approximate number of users
currently visiting the site ?

--
Patrice

"_Who" <Ca**********@roadrunner.coma 閏rit dans le message de groupe
de discussion : Of**************@TK2MSFTNGP06.phx.gbl...
There is much JavaScript cookie code on the Internet and in books, that
shows how to write, read, and take apart what is read.
I have some saved. I was wondering if there is any reason for me to
save that.

Also, I work alone so it would be valuable to hear that using
Request.Cookies and Response.Cookies is a good approach not
withstanding all the code that uses document.cookie.

It's confusing. For example your statement: "For example if you have to
set them client side... "
Is there some reason to do that?

In fact, I'm looking at a 75-line code that is used to display the
number of visits by the person to the site. It uses document.cookie and
JavaScript. Is that the way you'd do it?

Thanks for helping


Sep 18 '08 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Drew | last post: by
4 posts views Thread by James Johnson | last post: by
1 post views Thread by Alex Nitulescu | last post: by
5 posts views Thread by Miljana | last post: by
3 posts views Thread by Arpan | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.