364,032 Members | 4475 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

ASP.Net cookie -> ASP -> ASP.Net

Ben
P: n/a
Ben
I'm having problems with cookies from asp.net to asp back to asp.net.

It seems like I can set a cookie in asp.net fine, and alter it at will, as
soon as asp touches it, asp.net won't have anything to do with it. Can
someone please help!

The code below, going from aspx to aspx, works great the cookie as expected
goes from qwerty to zxcvb and back. As soon as you hit the asp page, the
cookie goes to asdfg and stays there no matter how many times you hit it
from the aspx pages afterwards.

Please help! I really want to transition slowly to .net, this will hamper
my ability to do that...

Thanks,
Ben

[fooo.aspx.cs]

private void Page_Load(object sender, System.EventArgs e)
{
if (Request.Cookies["Test"] != null &&
Request.Cookies["Test"]["Testing"] != null)
{
Response.Write(Request.Cookies["Test"]["Testing"]);
}
Response.Cookies["Test"]["Testing"] = "qwerty";
Response.Write("<br><a href=\"fooo2.aspx\">zxcvb</a>");
Response.Write("<br><a href=\"foo2.asp\">asdfg</a>");
}

[fooo.aspx.cs]

[fooo2.aspx.cs]
private void Page_Load(object sender, System.EventArgs e)
{
if (Request.Cookies["Test"] != null &&
Request.Cookies["Test"]["Testing"] != null)
{
Response.Write(Request.Cookies["Test"]["Testing"]);
}
Response.Cookies["Test"]["Testing"] = "zxcvb";
Response.Write("<br><a href=\"fooo.aspx\">qwerty</a>");
}
[fooo2.aspx.cs]

[foo2.asp]
<%
Response.Write(Request.Cookies("Test")("Testing"))
Response.Cookies("Test")("Testing") = "asdfg"
Response.Write("<br><a href=""fooo.aspx"">qwerty</a>")
Response.End()
%>
[foo2.asp]



Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


Steven Cheng[MSFT]
P: n/a
Steven Cheng[MSFT]
Hi Ben,

From your description, you met the problem on sharing cookie value between
classic asp page and asp.net page, yes?

As for this problem, I think it's a normal behavior because the ASP and
ASP.NET have differernt hehavior on dealing with the cookie's path. The
ASP.NET will by default set the Cookie's Path as "/", its the site's root
path while the ASP will set it as the "/appname" , the Application's
path(virtual dir). That's why when after we editing a cookie via ASP page,
we can never deal with it through ASP.NET page again( the path has been
corrupted and the ASP.NET can't correctly handled it).

To resolve it, we can use either of the following means:
1. If you want to follow the ASP's rule, than manually set the cookie's
path as "/appname", such as
Response.Cookies["newfoo"].Path = "/MyWebApp";
Response.Cookies["newfoo"].Value = "fooovalue";

2. Or set all the cookie's path as "/" in asp code, just like:
Response.Cookies("newfoo").Path = "/"
Response.Cookies("newfoo") = "aspValue"

I prefer the #2 one, and I 've done a test via the following pages:

===================================

##fooo.aspx
if (Request.Cookies["newfoo"] != null)
{
Response.Write("<br>" + Request.Cookies["newfoo"].Domain);
Response.Write("<br>"+ Request.Cookies["newfoo"].Path );
Response.Write("<br>" + Request.Cookies["newfoo"].Value);
}
Response.Cookies["newfoo"].Path = "/";
Response.Cookies["newfoo"].Value = "fooovalue";

Response.Write("<br><a href=\"fooo2.aspx\">fooo2.aspx</a>");
Response.Write("<br><a href=\"foo2.asp\">foo2.asp</a>");


##fooo2.aspx
if (Request.Cookies["foo"] != null )
{
Response.Write("<br>" + Request.Cookies["newfoo"].Domain);
Response.Write("<br>"+ Request.Cookies["newfoo"].Path );
Response.Write("<br>" + Request.Cookies["newfoo"].Value);
}
Response.Cookies["newfoo"].Path = "/";
Response.Cookies["newfoo"].Value = "fooo2value";
Response.Write("<br><a href=\"fooo.aspx\">fooo.aspx</a>");



##foo2.asp
<%
for each cookie in Request.Cookies
Response.Write( cookie & "=" & Request.Cookies(cookie) & "Path:" &
"<br>")
next
Response.Cookies("newfoo").Path = "/"
Response.Cookies("newfoo") = "aspValue"
Response.Write("<br><a href=""fooo.aspx"">fooo.aspx</a>")
Response.End()
%>

===============================================

That works ok. And here is a web link which has demonstrated the things I
mentioned above. Thanks.
#Cookie Behavior in Classic ASP-->ASP.NET
http://www.eggheadcafe.com/PrintSear...asp?LINKID=639


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx


Nov 18 '05 #2

Ben
P: n/a
Ben
Thanks for the fast response. I see what you're talking about, but I'm not
sure it applies to my problem.

In my example code from my original post, I can read the cookie in asp.net
and modify it at will. Asp can also read the cookie. As soon as asp
modifies the cookie, asp.net can read but not modify the cookie. I can see
the cookie in asp.net after asp changed it. The value is there as expected,
but asp.net can no longer modify the cookie.

Thanks,
Ben

"Steven Cheng[MSFT]" <v-schang@online.microsoft.com> wrote in message
news:EOA0ZAGREHA.1516@cpmsftngxa10.phx.gbl...[color=blue]
> Hi Ben,
>
> From your description, you met the problem on sharing cookie value between
> classic asp page and asp.net page, yes?
>
> As for this problem, I think it's a normal behavior because the ASP and
> ASP.NET have differernt hehavior on dealing with the cookie's path. The
> ASP.NET will by default set the Cookie's Path as "/", its the site's root
> path while the ASP will set it as the "/appname" , the Application's
> path(virtual dir). That's why when after we editing a cookie via ASP page,
> we can never deal with it through ASP.NET page again( the path has been
> corrupted and the ASP.NET can't correctly handled it).
>
> To resolve it, we can use either of the following means:
> 1. If you want to follow the ASP's rule, than manually set the cookie's
> path as "/appname", such as
> Response.Cookies["newfoo"].Path = "/MyWebApp";
> Response.Cookies["newfoo"].Value = "fooovalue";
>
> 2. Or set all the cookie's path as "/" in asp code, just like:
> Response.Cookies("newfoo").Path = "/"
> Response.Cookies("newfoo") = "aspValue"
>
> I prefer the #2 one, and I 've done a test via the following pages:
>
> ===================================
>
> ##fooo.aspx
> if (Request.Cookies["newfoo"] != null)
> {
> Response.Write("<br>" + Request.Cookies["newfoo"].Domain);
> Response.Write("<br>"+ Request.Cookies["newfoo"].Path );
> Response.Write("<br>" + Request.Cookies["newfoo"].Value);
> }
> Response.Cookies["newfoo"].Path = "/";
> Response.Cookies["newfoo"].Value = "fooovalue";
>
> Response.Write("<br><a href=\"fooo2.aspx\">fooo2.aspx</a>");
> Response.Write("<br><a href=\"foo2.asp\">foo2.asp</a>");
>
>
> ##fooo2.aspx
> if (Request.Cookies["foo"] != null )
> {
> Response.Write("<br>" + Request.Cookies["newfoo"].Domain);
> Response.Write("<br>"+ Request.Cookies["newfoo"].Path );
> Response.Write("<br>" + Request.Cookies["newfoo"].Value);
> }
> Response.Cookies["newfoo"].Path = "/";
> Response.Cookies["newfoo"].Value = "fooo2value";
> Response.Write("<br><a href=\"fooo.aspx\">fooo.aspx</a>");
>
>
>
> ##foo2.asp
> <%
> for each cookie in Request.Cookies
> Response.Write( cookie & "=" & Request.Cookies(cookie) & "Path:" &
> "<br>")
> next
> Response.Cookies("newfoo").Path = "/"
> Response.Cookies("newfoo") = "aspValue"
> Response.Write("<br><a href=""fooo.aspx"">fooo.aspx</a>")
> Response.End()
> %>
>
> ===============================================
>
> That works ok. And here is a web link which has demonstrated the things I
> mentioned above. Thanks.
> #Cookie Behavior in Classic ASP-->ASP.NET
> http://www.eggheadcafe.com/PrintSear...asp?LINKID=639
>
>
> Regards,
>
> Steven Cheng
> Microsoft Online Support
>
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
> Get Preview at ASP.NET whidbey
> http://msdn.microsoft.com/asp.net/whidbey/default.aspx
>
>[/color]



Nov 18 '05 #3

Ben
P: n/a
Ben
Ok, I was wrong :)

Thanks,
Ben

"Ben" <ben@online.nospam> wrote in message
news:RIGtc.764$pE2.657@fe37.usenetserver.com...[color=blue]
> Thanks for the fast response. I see what you're talking about, but I'm[/color]
not[color=blue]
> sure it applies to my problem.
>
> In my example code from my original post, I can read the cookie in asp.net
> and modify it at will. Asp can also read the cookie. As soon as asp
> modifies the cookie, asp.net can read but not modify the cookie. I can[/color]
see[color=blue]
> the cookie in asp.net after asp changed it. The value is there as[/color]
expected,[color=blue]
> but asp.net can no longer modify the cookie.
>
> Thanks,
> Ben
>
> "Steven Cheng[MSFT]" <v-schang@online.microsoft.com> wrote in message
> news:EOA0ZAGREHA.1516@cpmsftngxa10.phx.gbl...[color=green]
> > Hi Ben,
> >
> > From your description, you met the problem on sharing cookie value[/color][/color]
between[color=blue][color=green]
> > classic asp page and asp.net page, yes?
> >
> > As for this problem, I think it's a normal behavior because the ASP and
> > ASP.NET have differernt hehavior on dealing with the cookie's path. The
> > ASP.NET will by default set the Cookie's Path as "/", its the site's[/color][/color]
root[color=blue][color=green]
> > path while the ASP will set it as the "/appname" , the Application's
> > path(virtual dir). That's why when after we editing a cookie via ASP[/color][/color]
page,[color=blue][color=green]
> > we can never deal with it through ASP.NET page again( the path has been
> > corrupted and the ASP.NET can't correctly handled it).
> >
> > To resolve it, we can use either of the following means:
> > 1. If you want to follow the ASP's rule, than manually set the cookie's
> > path as "/appname", such as
> > Response.Cookies["newfoo"].Path = "/MyWebApp";
> > Response.Cookies["newfoo"].Value = "fooovalue";
> >
> > 2. Or set all the cookie's path as "/" in asp code, just like:
> > Response.Cookies("newfoo").Path = "/"
> > Response.Cookies("newfoo") = "aspValue"
> >
> > I prefer the #2 one, and I 've done a test via the following pages:
> >
> > ===================================
> >
> > ##fooo.aspx
> > if (Request.Cookies["newfoo"] != null)
> > {
> > Response.Write("<br>" + Request.Cookies["newfoo"].Domain);
> > Response.Write("<br>"+ Request.Cookies["newfoo"].Path );
> > Response.Write("<br>" + Request.Cookies["newfoo"].Value);
> > }
> > Response.Cookies["newfoo"].Path = "/";
> > Response.Cookies["newfoo"].Value = "fooovalue";
> >
> > Response.Write("<br><a href=\"fooo2.aspx\">fooo2.aspx</a>");
> > Response.Write("<br><a href=\"foo2.asp\">foo2.asp</a>");
> >
> >
> > ##fooo2.aspx
> > if (Request.Cookies["foo"] != null )
> > {
> > Response.Write("<br>" + Request.Cookies["newfoo"].Domain);
> > Response.Write("<br>"+ Request.Cookies["newfoo"].Path );
> > Response.Write("<br>" + Request.Cookies["newfoo"].Value);
> > }
> > Response.Cookies["newfoo"].Path = "/";
> > Response.Cookies["newfoo"].Value = "fooo2value";
> > Response.Write("<br><a href=\"fooo.aspx\">fooo.aspx</a>");
> >
> >
> >
> > ##foo2.asp
> > <%
> > for each cookie in Request.Cookies
> > Response.Write( cookie & "=" & Request.Cookies(cookie) & "Path:" &
> > "<br>")
> > next
> > Response.Cookies("newfoo").Path = "/"
> > Response.Cookies("newfoo") = "aspValue"
> > Response.Write("<br><a href=""fooo.aspx"">fooo.aspx</a>")
> > Response.End()
> > %>
> >
> > ===============================================
> >
> > That works ok. And here is a web link which has demonstrated the things[/color][/color]
I[color=blue][color=green]
> > mentioned above. Thanks.
> > #Cookie Behavior in Classic ASP-->ASP.NET
> > http://www.eggheadcafe.com/PrintSear...asp?LINKID=639
> >
> >
> > Regards,
> >
> > Steven Cheng
> > Microsoft Online Support
> >
> > Get Secure! www.microsoft.com/security
> > (This posting is provided "AS IS", with no warranties, and confers no
> > rights.)
> >
> > Get Preview at ASP.NET whidbey
> > http://msdn.microsoft.com/asp.net/whidbey/default.aspx
> >
> >[/color]
>
>
>[/color]



Nov 18 '05 #4

Post your reply

Help answer this question



Didn't find the answer to your ASP.NET question?

You can also browse similar questions: ASP.NET