Redirect to login page in correct language - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Redirect to login page in correct language

  • Redirect to login page in correct language
  • Hi,

    We have a site with 2 cultures (Turkish as default and English as 2nd language).
    I am interested in doing redirect to the login page but must be to the one in the right language.
    In Turkish it should be "~/giris" and in English "~/en/login".

    Right now I do this by saving the GUID of the login page and then call the PageManager like:
    PageManager pageManager = PageManager.GetManager();
    PageNode pageNode = pageManager.GetPageNode(loginPageGuidId);
    return pageNode.GetFullUrl();

    But isn't there a better way to get the login page Id? If we change the login page we need to remember to change code or we get all kind of exceptions. 

    I found these methods:
    SystemManager.CurrentContext.CurrentSite.FrontEndLoginPageUrl : this one always returns "~/giris" no matter what language I am in.
    SystemManager.CurrentContext.CurrentSite.FrontEndLoginPageId : always returns the Guid.Empty, is this a bug or have I configured something wrong?

    What if I needed to redirect to another page, since we have urls different in each language, is there any better way than saving Guids in the code to make the redirects correct? Could I tag the pages somehow to say this is my login page, this is my pageX, pageY etc... something that goes cross language..
    Getting the Guids is not so easy to get, doing that we a debugger and reading the values... there must be some nicer way to do this.

  • Hi Mikkel,

    If you are placing the API that checks get the page ID and performs redirect at the page where the login widget is there is more effective way to get the current page ID or other properties with:

    //get the page ID
    var currentNode = SiteMapBase.GetActualCurrentNode();
                //retreive different node properties
                var urlName = currentNode.UrlName
                var iD = currentNode.Id

    To get the different url names of the same page you have to change the current culture on the Thread or use a method that accepts CultureInfo parameter, here are several approaches to do this:

    CultureInfo currentLanguage = new CultureInfo("en");
                Thread.CurrentThread.CurrentUICulture = currentLanguage;
                PageManager pm = PageManager.GetManager();
                UrlLocalizationService s = ObjectFactory.Resolve<UrlLocalizationService>();
                var pageNode = pm.GetPageNodes().Where(n => n.Title == pageName.Text).FirstOrDefault();
                // approach 1
                var node = PageHelper.GetPageNodeForLanguage(pageNode, currentLanguage);
                var urlForPage = node.GetFullUrl();
                //the correct url gets returned here.
                urlForPage = s.ResolveUrl(urlForPage, currentLanguage);
                //approach 2
                var approach2Url = pageNode.GetFullUrl();
                var approach3Url = pageNode.GetFullUrl(currentLanguage, false);
                var approach4Url = Page.ResolveUrl(approach3Url);
    Once the page url is retreived perform redirect.
    CultureInfo tk = new CultureInfo("tk");
               if (Thread.CurrentThread.CurrentUICulture == tk)
                  //get the page url and redirect

    Stanislav Velikov
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items