You can pass in options like language, additional virtual path arguments and a RequestContext. The method also provides additional overloads. The simple overload only requires a ContentReference to be passed in as the argument. The class has a method named GetUrl (it used to be called GetVirtualPath() but that is now obsolete). The UrlResolver is not an HTML helper method and needs to be called using the ServiceLocator. The UrlResolver API can be thought of as an advanced friendly Url solution. This is brilliant if you want to create a very basic anchor tag, however, what happens when you want to create something more complex? UrlResolver PageLink also has an overload that allows you to pass additional route information and styling information: Some examples of how to sue this helper can be seen here: This helper can take a PageData, PageReference, or LinkItem object and will spit out all the HTML required to render an anchor tag. Html.PageLink()Ī second option is to use the PageLink HTML helper. Page Url is probably my preferred choice for rendering a URL, we do have other options. This code will return the friendly Url for the page: An example of how to do this is shown below. This is done using the page objects LinkURL property. This method requires a pages internal Url to be passed into it. In UrlExtensions, you will come across the PageUrl helper. The Url() HTML helper lives in the namespace, within UrlExtensions. You can do this using the Url() HTML helper. In a lot of situations, you will simply want to display the current pages Url in a view. Out-of-the-box, Episerver provides several options and in this tutorial, I will show you all of them! First, we will look at the PageUrl property □□□ Url.PageUrl() If you look at the Alloy sample site, you can find a good example of how you can use the link resolver to create a friendly Url in code, however, sometimes you may want to create URLs in your views. A page ID isn't the worst thing in the world to pass as a query string parameter, however, why give a potential intruder more information than they need? If a hacker noticed this pattern, they could in theory be tempted to try and access hidden pages by experimenting with different Ids in a browser. Internal links are created using the page Id. If you only referenced other pages on the site using the internal CMS link you're also removing an extra layer of security. Using SEO friendly URLs within your pages are essential to improve the usability and accessibility of your website. In this tutorial, you will learn how to get the friendly URL for an Episerver CMS power page.
0 Comments
Leave a Reply. |