Vulnerability in EPiServer.Forms
A complete newbie question by I can't seem to find the answer to this...
How do I get a reference to a page by absolute URL, e.g. "/mysite/child/grand-child"
PageReference.ParseURL looks like the correct method, but what am I missing?
var url = "/mysite/child/grand-child";var pageRef = PageReference.ParseUrl(url); <-- returns PageReference.EmptyReferencevar page = DataFactory.Instance.GetPage(pageRef);
This works, but i'd rather not have the base url specified...
var url = new UrlBuilder("http://localhost:17000/CommittedQuitters/Today/Blow-Temptation/");object pageRef;Global.UrlRewriteProvider.ConvertToInternal(url, out pageRef);
Eventually I will end up with several sites and languages, so the tree structure would be like so for example, so ideally i'd like to be able to retrieve the reference relatively...
The way we have been replicating sites for testing purposes is just to copy paste/paste the node and setting the pageStartId in <siteSettings> web.config... waiting for our enterprise license so I may be completely wrong in the above so let me know.
Let me know if you need info.
I think you should/could use PermanentLinkUtility.GetPageReference() to get the PageReference from your url.
About the license, you don't need to wait, just order partner developer licence at license.episerver.com and you should get it automatic.
Actually, it is the demo license which is sent automatically right away.
The partner developer license order is handled manually by EPiServer in your country, but they usually send it quick (within the hour) if you order within the business hours :)
I have a developer license and this is sufficient for the moment, since it allows me to play around and figure out show to to things in EpiServer (I've previously worked in Sitecore so trying to figure out the differences). We have partner licenses being organised.
PermanentLinkUtility.GetPageReference() seems to require the fully qualified url with domain name, e.g.
var url = new UrlBuilder("http://localhost:17000/mysite/child/grand-child");var pageRef = PermanentLinkUtility.GetPageReference(url);
Mmm, not sure if I am looking at this incorrectly. Obviously I can add in domain dynamically to build up the URL, but how do you guys get a reference to page by path when you don't know the ID... Does my logic look correct or is there another way to do this?
Also, common localized text seems to be stored in xml files on disk (/lang/lang_EN.xml). Is it possible to move these from xml file into EpiServer tree instead. Current situation means these have to be edited by developers and when creating a new version of the site these will need to be replicated (and I have no idea how to do these when we have 2 sites both using english, but need slightly different text)
UK -> EN (en-gb)Malaysia -> Malay (ms-my) + en-gb
If i could get this into the tree the site editors could change them as required and the common control text could be loaded relative to the site node.
I notice that episerver uses the text from these lang files like so. These seems very ASP.NET globalization-esque...
<EPiServer:Translate runat="server" Text="/profile/login/password" />
Is there a way using a episever control to retrieve text from a page/template and output to the user, without using a <asp:literal /> control and setting in the code behind?
Ok, I have found the following control does what I need:
<EPiServer:Property runat="server" PropertyName="Intro" PageLink="961" />
But again, the PageLink ID needs to be specified, either here or setting it via CodeBehind. in SiteCore there is the equivelant tag, but notice we can specifiy the datasource, so point it at which ever page/template where we want the fieldname to be retrieved from:
<sc:FieldRenderer runat="server" FieldName="Intro" DataSource="/sitecore/content/ReferenceData" />
Why does Sitecore seems so much more flexible in its approach and use of XPath expressions. Surely you shouldn't have to bring in developers everytime you want to change common text? Argh!
Hmmm, many questions in the same thread...
Well, here are some answers:
Thanks Dan, I am learning more and more about EpiServer and differences in Sitecore... not entirely happy with the way it works but it is just different to Sitecore...
I've figured out most of what I need to do. Do you have any more information/article on the XPath selectors? Is it only only available for LanguageManager.Instance.Tranlate() or for other methods also, like PermanentLinkUtility.GetPageReference or traversing from CurrentPage?
To clarify, the xpath expressions used with the Translate method are typically used for template specific text. Page specific data is stored in the page, accessed by a PageData instance, typically the CurrentPage property to get the page currently being rendered. Either you use the Property control (which as mentioned, uses CurrentPage unless you specify differently) or by reading it from the PageData and displaying it in a literal etc.
In most cases you don't even have to think about the language of the PageData as you code, the correct language version will be selected for you depending on the globalization rules (url, users preferred language, fallback languages etc). The same goes for the Translate control / Translate method.
If you have reference data that is not static (say only some editors have the right to update it, but all editors should be able to display the data on a page) you could use Dynamic Content, or a system similar to what Deane described in his blog post: http://world.episerver.com/Blogs/Deane-Barker/Dates/2010/11/Simple-Token-Replacement/
I don't think I have ever needed to go from URL to PageData "manually" and that and the first time I got the question was only a few weeks back. So something tells me there is probably a more EPiServeresque way to do what you want to do. In what situations do you have the need to find the PageData corresponding to an URL?
Thanks, the Dynamic Content will definitely be handy. I've also been playing around with PageData, XML files and localisation and certainly am able to work around "work around" most things for the moment.
The example that I am specifically thinking about... We have several websites on the same instance of EpiServer (using Enterprise licence). We have custom logic in our code that requires certain settings on a per site basis.
-Root Folder- Site 1-- Settings-- Page 1-- Page 2- Site 2-- Page 1-- Page 2
Since EpiServer seems to be primarily based around Page ID's, how do I reference the Settings page for each site? I know what site I am running in from the Page Start ID (set in <site> in config)... I guess I could use a hash of Start Page URL + Settings and then use PermanentLinkUtility.GetPageReference(), but that somehow seems wrong...
For the moment I have a property set on the Start Page, and select the config for each specific site. There are certain changes we need to make when rolling out a new site, and this is relatively minor, so it may be that this goes in the checklist of things to do...
There is a property type called Page. Either put such a property on the start page or use a dynamic property (!= dynamic content) to point to the settings page used in each part of the page tree. Or just store the settings you need on the start page (you can create a special tab for it and access control that tab). This is the typical way to store configuration that (at least some) editors need to be able to change. Maybe this is what you did, in that case I suggest you keep that solution unless there is a problem with it?
You can always get the start page by PageReference.StartPage. So you can construct the PageData by calling var startPage = DataFactory.Instance.GetPage(PageReference.StartPage). Then you can get your settings properties from that page, or if you choose to store them on a separate page you get the reference to that page from the start page by var settingsPageRef = startPage["MySettingsPageProperty"] as PageReference, then use DataFactory to get that second page and read its properties.
Thanks Magnus. Yes, I did what you suggested in the first part of the answer (by using a POage property). That seems to solve the problem and works well. I was trying to go for a fully relative path based solution, but since this is one a very quick change, I don't think it is worth spending any time on or over complicating.
Was just making sure that there wasn't an easier way of doing what I wanted to achieve (and that it was correct). Having the setting in a separate tab also sounds like a good idea.
If you want something more relative to the page tree you can use a dynamic property. A dynamic property is inherited down the page tree, but can be redefined at any level (and then inherited from that level instead). If you use a dynamic property to point to your settings page you can use different settings pages in different subtrees and not just one settings page per site.
Thanks. I'll have another read through the link you gave and read up more on dynamic properties. For now the current set up works fine. In reality we need to make other config changes, have images re-cut, translate pages etc etc when launching a new site, so really changing one property is no big deal.
I'll bear this in mind when I refactor the code next though.