Scheduled job problem



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

#48887 Feb 21, 2011 7:36
  • Johan Björnfot
    Member since: 2004

    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()

    #48898 Feb 22, 2011 10:13
  • Shamrez Iqbal
    Member since: 2006


    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?

    #49560 Mar 23, 2011 13:44
  • Anders Hattestad
    Member since: 1996

    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

    #49564 Mar 23, 2011 14:21
  • Shamrez Iqbal
    Member since: 2006

    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.

    #49568 Mar 23, 2011 15:05
  • Anders Hattestad
    Member since: 1996

    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.

    #49582 Mar 23, 2011 18:51
  • Johan Björnfot
    Member since: 2004

    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:

    UriSupport.AddLanguageSelection(CurrentPage.StaticLinkURL, CurrentPage.LanguageBranch)


    #49591 Mar 24, 2011 7:36
    #49602 Mar 24, 2011 11:07