I am using Request.Cookies["cookiename"].Value.ToString(). I can read
the same cookie in ASP code.
If I say Request.Cookies("CookieName") in ASP that works fine..
Try either of these approaches :
1.
if(Request.Cookies["cookieName"] != null)
Label1.Text = Server.HtmlEncode(Request.Cookies["cookieName"].Value);
2.
if(Request.Cookies["cookieName"] != null)
{
HttpCookie aCookie = Request.Cookies["cookieName"];
Label1.Text = Server.HtmlEncode(aCookie.Value);
}
Before trying to get the value of a cookie, you should make sure that the cookie exists;
if the cookie does not exist, you will get a NullReferenceException exception.
Notice also that the HtmlEncode method was called to encode the contents of a cookie
before displaying it in the page. This makes certain that a malicious user has not added
executable script into the cookie.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
<icanh...@gmail.com> wrote in message news:17a3fab7-c885-4fa2...@v26g2000prm.googlegroups.com...
Then, either the code you're using doesn't read the cookie properly,
or the cookie isn't being set correctly.
Have you tried the code I posted to read cookies ?
As for setting cookies, here's 2 sample C# code fragments :
1.
Response.Cookies["userName"].Value = "patrick";
Response.Cookies["userName"].Expires = DateTime.Now.AddDays(1);
2.
HttpCookie aCookie = new HttpCookie("lastVisit");
aCookie.Value = DateTime.Now.ToString();
aCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(aCookie);
How are you setting the cookie ?
Are you expiring the cookie ?
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
<icanh...@gmail.com> wrote in message news:111448ed-1b1c-4f14...@z16g2000prn.googlegroups.com...
You may want to elaborate a bit on your architecture and/or what you are
trying to do...
--
Patrice
<icanh...@gmail.com> a écrit dans le message de groupe de discussion :
17a3fab7-c885-4fa2...@v26g2000prm.googlegroups.com...
As you talked about a "C# utility" rather than about an ASP.NET page, I was
thinking that this "C# utility" was directly called from the ASP page during
the same request. As i said earlier you may want to elaborate a bit on your
architecture so that we are 100 % sure about how ASP and ASP.NET interacts
in your design...
--
Patrice
"Patrice" <http://www.chez.com/scribe/> a écrit dans le message de groupe de
discussion : D9051416-6E51-4DA2...@microsoft.com...
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Patrice" <http://www.chez.com/scribe/> wrote in message news:D9051416-6E51-4DA2...@microsoft.com...
That should have been :
Cookies should be able to be read regardless
of the language/platform used to write them.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Juan T. Llibre" <nomail...@nowhere.com> wrote in message news:%23VT45m6...@TK2MSFTNGP02.phx.gbl...
> Cookies should be able to be read regardless
> of the language/platform used to write them.
Correct, though some languages like C# are case-sensitive, which may be the
issue here...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Cookie Interop - ASP -->ASPX:
There is a change in cookie behavior between ASP and ASPX. In brief: If you
do NOT
specifically set a cookie path, ASP will automatically set the path to:
your web application's name --
"/AppName"
If you do NOT specifically set a path, ASPX will automatically set the path
to:
your server name --
"/"
To make ASP behave like ASPX, then add --
Response.Cookies("...").Path = "/" -- to your ASP code
To make ASPX behave like ASP, then add --
MyCookieObject.Path = "/AppName" -- to your ASPX code.
--Peter
<icanh...@gmail.com> wrote in message
news:111448ed-1b1c-4f14...@z16g2000prn.googlegroups.com...
Juan T. Llibre wrote:
Re: ASP NET 2.0 Cookie
06-May-08
re:
!> I am using Request.Cookies["cookiename"].Value.ToString()
Try either of these approaches :
1.
if(Request.Cookies["cookieName"] != null)
Label1.Text = Server.HtmlEncode(Request.Cookies["cookieName"].Value);
2.
if(Request.Cookies["cookieName"] != null)
{
HttpCookie aCookie = Request.Cookies["cookieName"];
Label1.Text = Server.HtmlEncode(aCookie.Value);
}
Before trying to get the value of a cookie, you should make sure that the cookie exists;
if the cookie does not exist, you will get a NullReferenceException exception.
Notice also that the HtmlEncode method was called to encode the contents of a cookie
before displaying it in the page. This makes certain that a malicious user has not added
executable script into the cookie.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espa?ol : http://asp.net.do/foros/
======================================
<icanh...@gmail.com> wrote in message news:17a3fab7-c885-4fa2...@v26g2000prm.googlegroups.com...
Previous Posts In This Thread:
On Tuesday, May 06, 2008 1:06 PM
Juan T. Llibre wrote:
Re: ASP NET 2.0 Cookie
re:
!> I am using Request.Cookies["cookiename"].Value.ToString()
Try either of these approaches :
1.
if(Request.Cookies["cookieName"] != null)
Label1.Text = Server.HtmlEncode(Request.Cookies["cookieName"].Value);
2.
if(Request.Cookies["cookieName"] != null)
{
HttpCookie aCookie = Request.Cookies["cookieName"];
Label1.Text = Server.HtmlEncode(aCookie.Value);
}
Before trying to get the value of a cookie, you should make sure that the cookie exists;
if the cookie does not exist, you will get a NullReferenceException exception.
Notice also that the HtmlEncode method was called to encode the contents of a cookie
before displaying it in the page. This makes certain that a malicious user has not added
executable script into the cookie.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espa?ol : http://asp.net.do/foros/
======================================
<icanh...@gmail.com> wrote in message news:17a3fab7-c885-4fa2...@v26g2000prm.googlegroups.com...
On Tuesday, May 06, 2008 1:37 PM
Juan T. Llibre wrote:
Re: ASP NET 2.0 Cookie
re:
!> I know how to read the cookie.
!> The problem is when I try to read it in C# it always returns null.
Then, either the code you're using doesn't read the cookie properly,
or the cookie isn't being set correctly.
Have you tried the code I posted to read cookies ?
As for setting cookies, here's 2 sample C# code fragments :
1.
Response.Cookies["userName"].Value = "patrick";
Response.Cookies["userName"].Expires = DateTime.Now.AddDays(1);
2.
HttpCookie aCookie = new HttpCookie("lastVisit");
aCookie.Value = DateTime.Now.ToString();
aCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(aCookie);
How are you setting the cookie ?
Are you expiring the cookie ?
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espa?ol : http://asp.net.do/foros/
======================================
<icanh...@gmail.com> wrote in message news:111448ed-1b1c-4f14...@z16g2000prn.googlegroups.com...
On Tuesday, May 06, 2008 1:42 PM
Patrice wrote:
I'm really not sure you can do that... ASP And ASP.NET are separate engines...
I'm really not sure you can do that... ASP And ASP.NET are separate
engines... I'm even surprised you don't get an exception as from the point
of view of the C# utility (how do you run this one ? This is exposed as a
com object ?) there is IMO no current (ASP.NET) request...
You may want to elaborate a bit on your architecture and/or what you are
trying to do...
--
Patrice
<icanh...@gmail.com> a ?crit dans le message de groupe de discussion :
17a3fab7-c885-4fa2...@v26g2000prm.googlegroups.com...
On Tuesday, May 06, 2008 1:50 PM
Patrice wrote:
Or do you mean you just transfer control from an ASP page to an ASPX page as
Or do you mean you just transfer control from an ASP page to an ASPX page as
Juan seems to have understood from your description ?
As you talked about a "C# utility" rather than about an ASP.NET page, I was
thinking that this "C# utility" was directly called from the ASP page during
the same request. As i said earlier you may want to elaborate a bit on your
architecture so that we are 100 % sure about how ASP and ASP.NET interacts
in your design...
--
Patrice
"Patrice" <http://www.chez.com/scribe/> a ?crit dans le message de groupe de
discussion : D9051416-6E51-4DA2...@microsoft.com...
On Tuesday, May 06, 2008 2:48 PM
Juan T. Llibre wrote:
Cookies should be able to read regardlessof the language/platform used to
Cookies should be able to read regardless
of the language/platform used to write them.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espa?ol : http://asp.net.do/foros/
======================================
"Patrice" <http://www.chez.com/scribe/> wrote in message news:D9051416-6E51-4DA2...@microsoft.com...
On Tuesday, May 06, 2008 6:25 PM
Juan T. Llibre wrote:
Typo alert...
Typo alert...
That should have been :
Cookies should be able to be read regardless
of the language/platform used to write them.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espa?ol : http://asp.net.do/foros/
======================================
"Juan T. Llibre" <nomail...@nowhere.com> wrote in message news:%23VT45m6...@TK2MSFTNGP02.phx.gbl...
On Tuesday, May 06, 2008 7:15 PM
Mark Rae [MVP] wrote:
Re: ASP NET 2.0 Cookie
Correct, though some languages like C# are case-sensitive, which may be the
issue here...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
On Wednesday, May 07, 2008 8:08 PM
Peter Bromberg [C# MVP] wrote:
Make sure the Path property of your cookie is set. , e.g. "/".
Make sure the Path property of your cookie is set. , e.g. "/". There are
minor inconsistencies in classic ASP cookies and ASP.NET cookies.
Peter
On Wednesday, May 07, 2008 8:12 PM
Peter Bromberg [C# MVP] wrote:
Re: ASP NET 2.0 Cookie
To be more specific:
Cookie Interop - ASP -->ASPX:
There is a change in cookie behavior between ASP and ASPX. In brief: If you
do NOT
specifically set a cookie path, ASP will automatically set the path to:
your web application's name --
"/AppName"
If you do NOT specifically set a path, ASPX will automatically set the path
to:
your server name --
"/"
To make ASP behave like ASPX, then add --
Response.Cookies("...").Path = "/" -- to your ASP code
To make ASPX behave like ASP, then add --
MyCookieObject.Path = "/AppName" -- to your ASPX code.
--Peter
<icanh...@gmail.com> wrote in message
news:111448ed-1b1c-4f14...@z16g2000prn.googlegroups.com...
On Thursday, May 08, 2008 7:08 AM
icanhelp3 wrote:
ASP NET 2.0 Cookie
I have a C# utility that runs in ASP website. When user logs in the
ASP code writes the cookie using Response.Cookie. I try to read the
same cookie in C#. I am unable to read it in C# code.
I am using Request.Cookies["cookiename"].Value.ToString(). I can read
the same cookie in ASP code.
If I say Request.Cookies("CookieName") in ASP that works fine..
On Thursday, May 08, 2008 7:08 AM
icanhelp3 wrote:
I know how to read the cookie.
I know how to read the cookie. The problem is when I try to read it in
C# it always returns null. In ASP it returns the value of the cookie.
Submitted via EggHeadCafe - Software Developer Portal of Choice
Book Review: C# 4.0 In a Nutshell [O'Reilly]
http://www.eggheadcafe.com/tutorials/aspnet/6dc05c04-c7f9-40cc-a2da-88dde2e6d891/book-review-c-40-in-a.aspx