Cross-origin Cookie Access
Easy Cross Domain cookies (sharing cookies between domains)
I own several websites that need memberships to post comments, and recently I wanted the ability to have a single login-so once the user is logged into one site they are automatically logged into the others.
Ideally, I cocould just write the login cookies for both domains from one location, or somehow share the same login cookie between the domains-but you quickly come up against browser security which (for good reason) doesn' t allow this sort of thing.
There are plenty of ways of solving this problem-but this is the simplest I cocould find. It uses an IFRAME to set cookies on the foreign domain.
In the example, you have Domain A which the visitor is currently on, and Domain B, which you want to set cookies on.
Add a page 'framelogin. aspx 'To Your Domain B website.
Public partial class framelogin inherits system. web. UI. page protected sub page_load (byval sender as object, byval e as system. eventargs) handles me. load dim suserid as string httpcontext. current. response. addheader ("p3p", "cp = \" "idc dsp cor ADM Devi taII psa psd ivai ivdi coni his our ind CNT \") suserid = request. querystring ("userid") dim ocookie as new httpcookie ("userid") ocookie. value = suserid ocookie. expires = datetime. now. adddays (1000) httpcontext. current. response. cookies. add (ocookie) ocookie = nothing end subend class
Note that the p3p header has been added, this is to allow 3rd party cookies.
To call this page, we insert code into the appropriate 'login' function in your domain a website.
private function login (byval susername as string, byval spassword as string) as Boolean dim iuserid as integer iuserid = checkloginokandgetuserdid (susername, spassword) if iuserid <> 0 then login = true response. write (" ") else login = false end if end function
Once the cookie has been set on Domain B I can use it to auto-login my visitors when they get there.
Also: For simplicity, I am using an IFRAME to call a page. If I wanted faster execution I cocould substitute an ihttphandler for the page.
This post brought to you by wegotdomain.com-over 10,000 aged domains for sale!
Related posts:
- Copying cookies using SS domains in ASP. NET
- We got domain-over 10,000 aged domains for sale
- How to Set third-party cookies with IFRAME Facebook applications
- Free Pr2 domains (and one Pr3)
- Opening a new browser window with post data