I have an ASP.Net MVC site that has a subdomain for each customer e.g. customer1.site.com, customer2.site.com, etc.
Login works fine from customer1.site.com/login and customer2.site.com/login using the standard ASP.Net FormsAuthentication.
How can I login from the parent domain (e.g. site.com/login) where the user specifies the subdomain name in a form field? I'd like the auth cookie to be stored against customer1.site.com or customer2.site.com so obviously need to redirect and repost the login form somehow.
you need to set the forms auth cookie domain to ".site.com" (note the leading .)
see here for setting the cookie domain: http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.cookiedomain(v=VS.100).aspx
I ended up solving this by splitting this into two separate pages. On the first page the user can enter the subdomain name (e.g. customer1) only in a form, on submitting the form they are redirected to the subdomain login page (e.g. customer1.site.com/login).