Johnny Johnny - 3 months ago 44
ASP.NET (C#) Question

mvc - multiple domains for single page with single login

I have MVC 4 website, where are 4 access points :

1.www.domain.com
2. domain.com

3.www.domain.net
4. domain.net


Problem is, that when user is logged on one of these url addresses, then user is not logged on another urls. So, for example after login to "www.domain.com" user is not logged in to "domain.com", this behavior applies for all access points.

User can be logged on all access points in same time, but he must fill login form 4 times.

There can be URL rewrite from non-www to www, but there are still 2 domains (.com/.net).

In IIS are all hostname shapes in single site bindings.

Any idea what I am doing wrong?

Answer

I have a website with similar domain extensions, including the https protocol, I forwarded all other domains to https://www.domain.com, its good for SEO reasons as well and for your analytics, I would suggest forward all domains to one single domain.

This answer also says:

So, how to share the authentication cookie across multiple domains? Well, there is absolutely no way to do that. The fundamental barrier of the HTTP protocol prevents you from sharing a cookie across different domains, primarily for security reasons.

...There is no built-in mechanism in ASP.NET to implement a Single Sign On across these two different sites.

You can redirect the website using web.config file by setting up sites in IIS to the redirect folder:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpRedirect enabled="true" destination="https://www.domainname.com$S$Q" exactDestination="true" httpResponseStatus="Permanent" />
    </system.webServer>
</configuration>