Search code examples
http-redirectauthenticationworkflowsitecorepreview

Redirect to original URL after login to Sitecore desktop


I'm having difficulties to understand how can I send a link to the next person in the workflow. So far I have something like http:/xxxx/?sc_mode=preview&sc_itemid=" + workflowItem.ID + "&sc_lang=en" The url is working fine but the problem is that the user is redirected to the login page. This makes sense so far but how can the user after the login be redirected again to the item that was linked? How can I extend the login method/pipeline to achieve this?

Maybe I'm trying something complex when it could be simple. Any other ideas?

Notes: I can't send the direct link to the item as the item is probably still in draft - master database and not on the web database.

Any help would be appreciated.

Thank you


Solution

  • You can achieve this by doing the following:

    1- Set this setting to true in web.config : Authentication.SaveRawUrl

    2- Create class called LoginRedirect:

    using System.Web;
    using Sitecore.Pipelines.LoggedIn;
    using Sitecore.Web;
    
    namespace Sitecore.SharedResources.Pipelines.Login {
    
     public class LoginRedirect : LoggedInProcessor {
    
    
        public override void Process(LoggedInArgs args) {
    
          if (Sitecore.Context.GetSiteName() != "login") { return; }
    
          string url = HttpUtility.UrlDecode(
              WebUtil.GetQueryString("url", "")
          );
          if (!string.IsNullOrWhiteSpace(url)) {
            WebUtil.Redirect(url);
          }
        }
    
      }
    }
    

    3- Create a config file inside your include folder with the following (replace your assembly name):

    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
      <sitecore>
        <processors>
          <loggedin>
            <processor mode="on"
                type="Sitecore.SharedResources.Pipelines.Login.LoginRedirect,
                      [Your Assmbly Name]" />
          </loggedin>
        </processors>
      </sitecore>
    </configuration>
    

    This will redirect the user after the login to the original URL.