Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Session Cookie not accessible across Sub-Domains

 
Thread Tools Search this Thread
Old 06-20-2008, 01:11 PM   #11
Default will it work on diff IIS servers as well


I have a situation where subsites are on different servers as in different machines.

Will i still be able to share cookie data.

www.example.com

subdomain themaster.example.com
another domain theslave.example.com

if the user logs in from any of the websites. Can all of them share the cookie.


chirdeep

Last edited by chirdeep : 06-20-2008 at 01:14 PM.
chirdeep is offline   Reply With Quote
Old 06-23-2008, 04:58 PM   #12
alecl
Junior Member
 
Join Date: Jun 2008
Posts: 1
Default Problem with Approach "...Domain = .mydomain.com"
I cannot get Doug's 'hack' to work and I’d really like some advice in about what I'm doing wrong. I've tried adding it to my Master Page and also within instances but no luck. My Session.SessionId is the same across subdomains but I can't share session objects (like Session["Example"]).

1. Does the session mode have to be out-of-proc or can it remain inproc? Mine is currently inproc with cookieless=false
2. Do I have to add any other code other than these two lines?
3. Can these lines of code be added somewhere like Page_Load or do they have to go in a special method EndRequest or Page_Unload?

Thanks
Alec


Quote:
Originally Posted by =?Utf-8?B?RG91Zw==?=
Well, the out-of-proc StateServer works just fine for sharing sessions across
sub-domains. Everything in ASP.NET allows for sharing sessions across
sub-domains; everything except this simple cookie issue.

Let me explain one of the reasons why I need sessions to be shared across
sub-domains:
I have a "www" server, and a "search" server. When a person signs in, the
HTML header at the top of every page shows a link to "Sign Out". This same
header is used on every page throughout the site; on both "www" and "search".
Based on the session, I know whether the person is signed in or not, and
whether to show the "Sign Out" link or not. The session needs to persist
across sub-domains; otherwise, when a person goes to the "search" server,
they wouldn't appear to be signed in any longer.

There are many real-world examples of why sessions need to be shared across
sub-domains. e.g. Yahoo uses a single sign-on and you stay signed-in across
"mail.yessy.com", "shopping.yahoo.com", "music.yahoo.com", etc.

There are just so many examples of why a session would need to be shared
across sub-domains.

The ASP.NET StateServer natively supports sub-domains. The only issue is the
domain setting for the Session cookie. Instead of tying the cookie to
"www.mydomain.com", allow the cookie to be tied to "mydomain.com". That way,
all sub-domains can access the cookie and problem solved. People stay
signed-in across sub-domains; the same session can be accessed; etc.

Why not allow developers to share sessions across sub-domains if they need
to? It's an extremely simple feature to provide.

By the way, I implemented a fairly good fix/hack today. Put this code on
every page:
Response.Cookies["ASP.NET_SessionId"].Value = Session.SessionID;
Response.Cookies["ASP.NET_SessionId"].Domain = ".mydomain.com";

Those two lines of code rewrite the Session cookie so it's now accessible
across sub-domains.

My hope is that Microsoft will implement a web/machine.config param that
allows the Session cookie to be accessed across sub-domains.

Doug



"John Timney (ASP.NET MVP)" wrote:

> I expect the problem would be the same. Asp.net bounds sessions and objects
> within applications for security, so if your subdomains were not part of the
> same web application then the session would not apply. The solution could
> be to have a root application, with all your other applications hanging
> under it as non application virtual directories - and then have something
> like the isapi virtual hosting filter handle the domains, allowing the root
> application to own the single session. I've never tried it myself though.
> I would always see a sub-domain as a seperate application entirely, or why
> would it be a sub-domain?
>
> --
> Regards
>
> John Timney
> ASP.NET MVP
> Microsoft Regional Director
>
> "Doug" <> wrote in message
> news:BD97499C-A4EB-4E95-9165-...
> > Hi John,
> > I wasn't referring to sharing sessions across parent domains (e.g.
> > "mydomain1.com" and "mydomain2.com"). I want to share sessions on
> > sub-domains
> > of the same domain (e.g. "www.mydomain.com" and "search.mydomain.com").
> > Regards,
> > Doug
> >
> >
> > "John Timney (ASP.NET MVP)" wrote:
> >
> >> sorry I misread your question (its late here!!).
> >>
> >> You can't share sessions across domains, nor applications natively - so
> >> it
> >> will always set a new cookie as you move between domains. Because you
> >> can
> >> share cookies across those applications (and between those domains) one
> >> approach is to store your shared data in a database and use a shared
> >> domain
> >> cookie to identify the data in the database.
> >>
> >> --
> >> Regards
> >>
> >> John Timney
> >> ASP.NET MVP
> >> Microsoft Regional Director
> >>

>
>
>


alecl
alecl is offline   Reply With Quote
Old 04-30-2009, 02:27 PM   #13
zubairmasoodi
Junior Member
 
Join Date: Apr 2009
Posts: 1
Default
Hi Doug

Can you please let me know how did you solved this problem. i have been looking along three days on internet to solve this menace but to no avail. also if possible for you please give me your email, so that i can communicate to you.

Thanks


zubairmasoodi
zubairmasoodi is offline   Reply With Quote
Old 07-03-2009, 08:19 PM   #14
tewehner
Junior Member
 
Join Date: Jul 2009
Posts: 1
Default
Here is a solution I have used in the past that at least alleviated the need to add code to every page:

In the Global.asax file:

void Application_EndRequest(object sender, EventArgs e)
{
if (Response.Cookies["ASP.NET_SessionId"] != null)
{
Response.Cookies["ASP.NET_SessionId"].Domain = ".mydomain.com";
}
}


tewehner
tewehner is offline   Reply With Quote
Old 11-06-2009, 11:09 PM   #15
anilchanna
Junior Member
 
Join Date: Nov 2009
Posts: 1
Default Session Cookie not accessible across Sub-Domains
Hi,

We have tried the same approach suggested by you in one of our application. But the problem is that it is working fine locally at my computer but not on our production server. Is there some other setting I am missing? Could you please suggest some solution?

It is bit urgent. Can you please give me a quick suggestion?

Thanks in advance.

Anil


anilchanna
anilchanna is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.Net Session Cookie Lost on mozilla/netscape After return from cross domain saurabhm Software 3 09-18-2009 12:36 PM
Session Expired too soon lidya_usq Software 0 09-24-2008 02:46 AM
How to spawn a session in new window using expectk Chets General Help Related Topics 0 10-16-2007 09:34 AM
Attempted to access a field that is not accessible by the caller. reshma24pc Software 0 07-21-2007 11:51 AM
Transfering ASP Session to ASPX Session kalim Software 0 07-12-2007 03:38 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46