Please check the following code.
PageData StartPage = EPiServer.DataFactory.Instance.GetPage(new PageReference(Int32.Parse(StartPageID)))
The above code behaving differently when i run the job manually and automatically
when run the job manually.....the above code writtens startpage.LinkURL="default.aspx?id=45"(without epslanguage)
when scheduled job runs automatically..the same above code writtens startpage.LinkURL="default.aspx?id=45&epslanguage=lv".
The start page is not difined in "lv" language and also "lv" is not fallback and master language for the startpage.
so here my question is why scheduled job appending the "epslanguage=lv" to the above code when run automatically.
My scheduled jobas behaving differently because of the above problem..please advice me in this case.
Thanks in advance
The reason for the different behaviour when running manually and automatically is that ContentLanguage.PreferedCulture is resolved differently. When you start a job manually the job will execute on the thread serving the web request the user initiated, meaning the language context for the job will be the same as the user has. When running the job autmatically on the other hand the job will be executed on a worker thread, ContentLanguage.PreferedCulture in that case will probably be set to LanguageBranch.FirstEnabled() (in your case "lv").
To get your job to behave the same way regardless if the job is executed manually or automatically you should use an overload to GetPage that takes an ILanguageSelector, e.g. LanguageSelector.MasterLangauge()
I'm having similar problems and it seems no matter which IlanguageSelector implementation i choose, be it AutoDetect or MasterLanguage I always get the final "fallback" language even though I've specified in the globalization settings that I do not want to use that language, any other suggestions for this?
The LinkURL property dosn't check what language the page is in, but uses as Johan says ContentLanguage.PreferedCulture.Name
the easy fix is to create this link by adding epslanguage="+page.languageID
Hi Anders, thanks, doing a quick test you are correct that the languageid field contains the correct language, a little bit strange though that LinkURL doesn't work with this. And that I therefore have correct the language manually.
I agree with you. Its very strange. Its even more strange when you are in one language, and get's a page in another language. Then the language path of the url will not be thats pages language.
The reason that PageData.LinkURL returns links with a language set to ContentLanguage.PreferedCulture instead of the actual language of the PageData instance is to avoid unattended language switches when browsing the site. An example of that could be a menu control that binds to some collection (as it works now all generated links for the menu will follow the language the user is on regardless if some item in the collection acually is of a different langauge).
PageData has an additional property StaticLinkURL that does not contain language information. You can use this in combination with property LanguageBranch to build an url for the language the pagedata instance like: