How to Stay Authenticated while Switching among Second and Third Level Domain Sites

   —   
This article describes how to modify the login page to allow users stay authenticated between sites running on third and second level domains, assuming that all sites are running under one Kentico installation and in one virtual directory.
If you are running multiple sites using second/third level domains (for example domain.com, dev.domain.com, public.domain.com), you can modify the login page to authenticate users for each of the above sites after the login form is filled in successfully.

How to do it?

1. You will need to modify the ~/CMSPages/logon.aspx.cs page, , specifically the Login1_LoggedIn method.

2. Add the following code into the Login1_LoggedIn method:

System.Web.HttpCookie MyCookie = System.Web.Security.FormsAuthentication.GetAuthCookie(Login1.UserName, false);

string[] domainParts = UrlHelper.GetCurrentDomain().Split('.');

if (domainParts.Length > 1)
{
string secondLevelDomain = domainParts[domainParts.Length - 2] + "." + domainParts[domainParts.Length - 1];

MyCookie.Domain = secondLevelDomain;
Response.AppendCookie(MyCookie);
}

3. Now if you log in to the system, you can switch between sites (for example in the CMS Desk) without being redirected to the login page.

-it-


See also: Single sign on article

Applies to: Kentico CMS 5.5, 5.5 R2
Share this article on   LinkedIn Google+