Passing Cookies

T

Tom

I know how to create a cookie using the HttpCookie.
I know about setting its domain so it can be shared.


So I have created a cookie on web site A and set it to
expire in 10 minutes.

Now I am on web site B, in VS.NET C# and I want to access
the cookie created on web site A.

Is this possible?

Can anyone advise??

Here is the code:

DateTime dt = DateTime.Now;
TimeSpan ts = new TimeSpan(0,0,10,0);

HttpCookie MyUIDCookie = new HttpCookie("MyCookie", "some
value");
MyUIDCookie.Domain = ".mydomain.com";
Response.Cookies.Add(MyUIDCookie);

MyUIDCookie.Expires = dt.Add(ts);
 
D

Dmitriy Lapshin [C# / .NET MVP]

Tom,

If the websites A and B are within the same domain, you can retrieve cookies
from the Cookies property of the HttpRequest instance available from the
Page's Request property.
 
T

Tom

Dimitria:

Yes, both web sites (A and B) are in the same domain.

And I tried these three attempts but "myCookie" always
returned null when I executed it on web site B in C#.

myCookie = Request.Cookies["MyPwdCookie"];
myCookie = HttpRequest.Current.Request.Cookies
["MyPwdCookie"];
myCookie = HttpContext.Current.Request.Cookies
["MyPwdCookie"];

HttpCookie myCookie = Page.Request.Cookies["MyPwdCookie"];

myCookie = HttpContext.Current.Request.Cookies
["MyPwdCookie"];


Can you advise further?
-----Original Message-----
Tom,

If the websites A and B are within the same domain, you can retrieve cookies
from the Cookies property of the HttpRequest instance available from the
Page's Request property.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Tom said:
I know how to create a cookie using the HttpCookie.
I know about setting its domain so it can be shared.


So I have created a cookie on web site A and set it to
expire in 10 minutes.

Now I am on web site B, in VS.NET C# and I want to access
the cookie created on web site A.

Is this possible?

Can anyone advise??

Here is the code:

DateTime dt = DateTime.Now;
TimeSpan ts = new TimeSpan(0,0,10,0);

HttpCookie MyUIDCookie = new HttpCookie ("MyCookie", "some
value");
MyUIDCookie.Domain = ".mydomain.com";
Response.Cookies.Add(MyUIDCookie);

MyUIDCookie.Expires = dt.Add(ts);

.
 
J

Jeffrey Tan[MSFT]

Hi Dmitriy,

As MSDN states, the cookies can be retrieved across the domains, please
refer to :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csvr2002/ht
m/cs_sp_security_uvmp.asp

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Dmitriy Lapshin [C# / .NET MVP]" <[email protected]>
| References: <[email protected]>
| Subject: Re: Passing Cookies
| Date: Fri, 3 Oct 2003 17:54:10 +0300
| Lines: 42
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| X-Original-NNTP-Posting-Host: engine.validio.com.ua
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: nexus.validio.com.ua 193.41.50.2
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl!nexus.validio
.com.ua!engine.validio.com.ua
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:188768
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Tom,
|
| If the websites A and B are within the same domain, you can retrieve
cookies
| from the Cookies property of the HttpRequest instance available from the
| Page's Request property.
|
| --
| Dmitriy Lapshin [C# / .NET MVP]
| X-Unity Test Studio
| http://x-unity.miik.com.ua/teststudio.aspx
| Bring the power of unit testing to VS .NET IDE
|
| | > I know how to create a cookie using the HttpCookie.
| > I know about setting its domain so it can be shared.
| >
| >
| > So I have created a cookie on web site A and set it to
| > expire in 10 minutes.
| >
| > Now I am on web site B, in VS.NET C# and I want to access
| > the cookie created on web site A.
| >
| > Is this possible?
| >
| > Can anyone advise??
| >
| > Here is the code:
| >
| > DateTime dt = DateTime.Now;
| > TimeSpan ts = new TimeSpan(0,0,10,0);
| >
| > HttpCookie MyUIDCookie = new HttpCookie("MyCookie", "some
| > value");
| > MyUIDCookie.Domain = ".mydomain.com";
| > Response.Cookies.Add(MyUIDCookie);
| >
| > MyUIDCookie.Expires = dt.Add(ts);
| >
| >
|
|
 
D

Dmitriy Lapshin [C# / .NET MVP]

Jeffrey,

Thanks for pointing out the issue.

The article you have referred to reads:

"Before sending a request, the client browser checks to see if a cookie is
available containing a domain property that ***matches the tail of the fully
qualified domain name of the host specified in the requested URL**. If such
a cookie exists, the path property of the cookie is compared to the path
name component of the requested URL. If they match, the cookie is sent with
the request"

According to the fragment enclosed in "***"s, I beleive, the original
poster's websites A and B should have the same top-level domain name, such
as

app1.company.com

and

app2.company.com

and the client's browser, let's say IE to be specific, will never send a
cookie having its Domain attribute set to "app1.company.com" with a request
being sent to "app1.anothercompany.com"? Could you please elaborate if I am
mistaken?
 
T

Tom Daria

Does anyone know if classic ASP Cookies object supports the ASP.NET
".domain" property?

Thanks

Tom
 
J

Jeffrey Tan[MSFT]

Hi Tom,

I found that you have asked if ASP.NET support the ".domain" property in
microsoft.public.vsnet.general queue with Subject:
"Cookie Domain Property"
And a colleague of mine has replied an answer to you, please follow up him
there, he will work with you.

Thanks for your understanding

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: Tom Daria <[email protected]>
| References: <#[email protected]>
| X-Newsreader: AspNNTP 1.50 (ActionJackson.com)
| Subject: Re: Passing Cookies
| Mime-Version: 1.0
| Content-Type: text/plain; charset="us-ascii"
| Content-Transfer-Encoding: 7bit
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Date: Mon, 06 Oct 2003 07:38:48 -0700
| NNTP-Posting-Host: actionjackson133.dsl.frii.net 216.17.147.133
| Lines: 1
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:189244
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Does anyone know if classic ASP Cookies object supports the ASP.NET
| ".domain" property?
|
| Thanks
|
| Tom
|
|
|
|
|
| Don't just participate in USENET...get rewarded for it!
|
 

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