Try our conversational search powered by Generative AI!

Scheduled job problem

Vote:
 

HI,

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
Vote:
 

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
Vote:
 

Hi, 

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
Vote:
 

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
Vote:
 

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
Vote:
 

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
Vote:
 

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
Vote:
 
#49602
Mar 24, 2011 11:07
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.