Sitecore Stuff and Such

- by Christian Kay Linkhusen


Single Sign On to the Sitecore desktop

When you use Sitecore Active Directory module it is possible to set up Single Sign On by protecting the file LDAPLogin.aspx with Windows Authentication. Then it is possible to login to Sitecore without entering username and password, when you enter the following URL: http://[yoursite]/sitecore/admin/LDAPLogin.aspx.
This will login the user to the Content Editor or the StartURL entered on the users User Profile in Sitecore.

But what if you want to make it possible for the users to decide for them self, if they would like to login to the Desktop or the Content Editor?
This is possible by using the following code. Create a webform with the name default.aspx with the following code in the code behind:    

protected void Page_Load(object sender, EventArgs e)
        string str = base.Request.ServerVariables["LOGON_USER"];
        string username = str.Split('\\').Last();
        if (string.IsNullOrEmpty(username))
            throw new Exception("There was an error resolving the username");


    private void DoLogin(string username)
        if (AuthenticationManager.Login("ad\\" + username))
            string returnurl = "/sitecore/shell/default.aspx?sc_lang=da";

            LoggedInArgs args = new LoggedInArgs
                Username = AuthenticationManager.GetActiveUser().Name,
                StartUrl = returnurl,
                Persist = true
            Pipeline.Start("loggedin", args);

            if (!string.IsNullOrEmpty(returnurl))
            string loginError = string.Format("Can't login the user '{0}'", username);
            Log.Warn(loginError, this);
            throw new Exception(loginError);

If you copy the file to a directory /login/desktop in your Sitecore solution, and protect the folder with Windows Authentication, it will now be possible to login to the Sitecore Desktop by entering the URL: http://[yoursite]/login/desktop

Add comment