Azure Websites - Subdomain Login Status Sharing

I have two websites on Azure websites and I use CNAME to use them with my own domain name.

Call the two sites site1.example.com and site2.example.com.

I am using ASP.NET MVC 4 and SimpleMembership. I want the user to be able to log into site1.example.com, and for this registered state, site2.example.com must be accepted.

Here is what I have done so far:

  • Both sites1 and site2 point to the same membership database (the connection string is set the same for both in web.config, and InitializeSimpleMembershipAttribute is set to view this connection string)
  • I set the cookie domain to .example.com (in the authentication section of web.config, system.web)
  • I manually set machineKey in config for system.web for the same thing for both sites

However, if I sign up for site1, I will not log in to site2. I see that cookie.ASPXAUTH is correctly set to .example.com, so it appears for both.

So what am I missing?

+4
source share
1 answer

If you use AJAX requests to log in (for example, via the web API), try turning on

xhrFields: { withCredentials: true } 

sort of

 $.ajax({ method: 'POST', url: 'yourloginurl.com/api/login', xhrFields: { withCredentials: true }, success: function (data) { ... } }); 

After installing the domain on httpCookie.

I spent a day to find this solution, and it will solve my problem.

0
source

All Articles