ASP.NET login to subdomain from parent domain

2019-07-03 07:49发布

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.

2条回答
Explosion°爆炸
2楼-- · 2019-07-03 08:34

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

查看更多
放荡不羁爱自由
3楼-- · 2019-07-03 08:45

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).

查看更多
登录 后发表回答