7

We are upgrading from 6.4 to 8.2 and we have some custom login pages for several clients. I used to be able to do something like this:

if (
(System.Web.Security.Membership.GetUser(usernameBox.Text).IsApproved) &&
(Sitecore.Security.Authentication.AuthenticationManager.Login(usernameBox.Text, passwordBox.Text, false))                
)
{
    redirectUrl = Page.Request.Url.GetLeftPart(System.UriPartial.Authority) + "/sitecore/shell/default.aspx";
    Response.Redirect(redirectUrl);
}

But if I do that now it sends me to the default Sitecore login page. I know that it logins them in and as long as I don't try to get into the content management part it is fine. It is like they are not getting the right cookie. Do I need to use something besides AuthenticationManager?

2
  • Where are you suppose to redirect them to? Commented Dec 20, 2017 at 15:13
  • We are sending them to the desktop but I have tried the launchpad too.
    – Jeremy
    Commented Dec 20, 2017 at 15:23

1 Answer 1

10

You have redirect user to "/sitecore" instead. You will also need to create the cookie by calling createticket function. Here's a snippet of what should be called after AuthenticationManager.Login.

AuthenticationManager.Login(userName);
string ticket = Sitecore.Web.Authentication.TicketManager.CreateTicket(userName, @"/sitecore/shell");
HttpContext current = HttpContext.Current;
if (current != null)
{
    HttpCookie cookie = new HttpCookie(Sitecore.Web.Authentication.TicketManager.CookieName, ticket)
    {
        HttpOnly = true
    };
    current.Response.AppendCookie(cookie);    
}

Make sure you test item preview and experience editor as you might experience other issues.

7
  • I tried it with just "/sitecore" but it still sends me to the default Sitecore login page.
    – Jeremy
    Commented Dec 20, 2017 at 16:13
  • Are these virtual users or existing sitecore users?
    – josedbaez
    Commented Dec 20, 2017 at 16:16
  • They are existing sitecore users.
    – Jeremy
    Commented Dec 20, 2017 at 16:19
  • weird. Can you try this function. We had to do it to fix preview, but might help you. Ill update the answer if it fixes it. josedbaez.com/2017/09/sitecore-okta-login/#ticket-function
    – josedbaez
    Commented Dec 20, 2017 at 16:20
  • That fixed it. I guessing it doesn't automatically create the tickets anymore.
    – Jeremy
    Commented Dec 20, 2017 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.