472,371 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 software developers and data experts.

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

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
3 1893
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
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-******@online.microsoft.com> wrote in message
news:EO**************@cpmsftngxa10.phx.gbl...
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 #3
Ben
Ok, I was wrong :)

Thanks,
Ben

"Ben" <be*@online.nospam> wrote in message
news:RI***************@fe37.usenetserver.com...
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-******@online.microsoft.com> wrote in message
news:EO**************@cpmsftngxa10.phx.gbl...
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 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sergio | last post by:
<HTML> <!- I need to write code that saves contents of the following form as MyForm.txt(only Last_Name,First_Name) into directory c:\MyPATH\MyForm.txt or into cookies directory. -->...
2
by: bissatch | last post by:
Hi, I am currently writing a simple PHP program that uses an XML file to output rows for a 'Whats New' page. Once written, I will only require updating the XML file and any pages that use the...
2
by: dave | last post by:
I have 2 pages... in the first page i check to see for the existance of the cookie, if found do something else set the value and set the cookie. (cookie gets set ok) I use the following code to...
4
by: Andrzej Wegrzyn | last post by:
Hi, I had a portal that worked before, and over 5 months period JavaScript errors started to show up on all forms where I have datagrids. Using: IE 6.0, WIN XP, IIS 5.1, Framework 1.1 ...
2
by: mit | last post by:
Hello friends , Here i have problem. I want to make the online job web site .But i donts know much about asp.net .so if any body provide me suggestion to how to create online resume database...
4
by: David Bargna | last post by:
Hi I have a problem, I have a string which needs to be converted to a byte array, then have the string representation of this array stored in an AD attribute. This string attribute then has to...
0
by: Eric | last post by:
Visual C++ 2005 Express MVP's and experience programmer's only please!... I need to get the number of lines in a textbox so I can insert them into a listview. The text comes from my database...
5
by: John Nagle | last post by:
This, which is from a real web site, went into BeautifulSoup: <param name="movie" value="/images/offersBanners/sw04.swf?binfot=We offer fantastic rates for selected weeks or days!!&blinkt=Click...
2
by: sf | last post by:
Hundsome Money Online Guaranteed payment month after month Work part time or full time as you like . Make quick good cash working 2 to 3 hours a day . Work anywhere from home/ office without...
0
by: reema | last post by:
EJB Interview Questions http://interviewdoor.com/technical/EJB-Interview-Questions.htm CSS Interview Questions http://interviewdoor.com/technical/CSS-Interview-Questions.htm C Interview Questions...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.