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

B

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]
 
S

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/PrintSearchContent.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
 
B

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 said:
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/PrintSearchContent.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
 
B

Ben

Ok, I was wrong :)

Thanks,
Ben

Ben said:
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 said:
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/PrintSearchContent.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
 

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

Top