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.
Regards,
Mikkel
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
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();
//approach3
var approach3Url = pageNode.GetFullUrl(currentLanguage,
false
);
//approach4
var approach4Url = Page.ResolveUrl(approach3Url);
CultureInfo tk =
new
CultureInfo(
"tk"
);
if
(Thread.CurrentThread.CurrentUICulture == tk)
//get the page url and redirect