Cross-origin cookies access easy cross domain cookies (sharing cookies between domains)

Source: Internet
Author: User

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:

    1. Copying cookies using SS domains in ASP. NET
    2. We got domain-over 10,000 aged domains for sale
    3. How to Set third-party cookies with IFRAME Facebook applications
    4. Free Pr2 domains (and one Pr3)
    5. Opening a new browser window with post data

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.