For forms authentication I used this in web.config (note the domain attribute):
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" name=".ASPXAUTH" protection="Validation" path="/" domain=".myserver.dev" />
</authentication>
How is a single sign-on across subdomains configured for the new ASP.NET Identity Framework in Mvc 5?
More Info:
I am creating a multitenant application. Each client will be on a subdomain:
client1.myapp.com
client2.myapp.com
I want a user to be able to sign on to client1.myapp.com
and then go to client2.myapp.com
and still be signed in. This was easy with forms authentication. I'm trying to figure out how to do it with the new Identity Framework.
EDIT
Here is the code that eventually worked for me:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Application",
LoginPath = "/Account/Login",
CookieDomain = ".myapp.com"
});
In Startup.Auth.cs, you will see something like:
for RC:
This was removed in RTM and replaced with the explicit configuration of the cookie auth:
The CookieAuthenticationOptions class has a CookieDomain property which is what you are looking for I believe.
You need to set up in web.config the same machineKey for ALL websites/applications.
All websites MUST HAVE at least this configuration.
http://msdn.microsoft.com/en-us/library/w8h3skw9(v=vs.85).aspx
This is an example
In the Startup.Auth.cs file, add the
CookieDomain
parameter with your domain:Then for all websites you need to set a unique machine key. The easiest way to generate a new one is using IIS:
Find the "Machine Key" option on your site:
Click the "Generate Keys" button to get your keys.
Finally, the above process will add the following to your
web.config
and you need to ensure that this is copied into each of your sites.This was driving me crazy until I learned that Identity 2.0 still depends on the machine key to encrypt the Authentication cookie. So if you want two instances of the same application on different sub-domains then you need to set the same machine key for each application.
So in summary:
Set identical machine keys in each application's web config
This answer led me to setting the values: Does ASP.NET Identity 2 use machinekey to hash the password?