Site Logo
How to get girlfriend or boyfriend > Russian > Episerver get friendly url from url property

Episerver get friendly url from url property

In one of our project I had to refactor a code responsible for generating XML feed. The feed contains information like title, description and URL. There are three languages enabled for the site: English, Swedish and Norwegian. All pages was first created in English and some page translations are missing for Norwegian and Swedish.

SEE VIDEO BY TOPIC: Pretty URLs - Remove IDs & Numbers for SEO Friendly URL Module

SEE VIDEO BY TOPIC: - Rewrite URL with htaccess

Get friendly Url of a page in EPiServer

Page 1 2 Maybe there are other posts about this, but I thought I'd share an easy way of getting the friendly URL of a page since I've gotten questions about it on numerous occasions:. So, you should probably not ignore the PageLink parameter unless you have to - URL rewriting is probably the most expensive operation carried out by EPiServer.

I'm a firm believer in avoiding querystring parameters in URLs, especially for public web sites. Security, SEO and esthetics are a few reasons why. Custom URL rewriting can help you avoid those ugly ampersands and question marks, even in cases where you want to use querystring parameters. Internally that is.

You'll see what I'm talking about in a little bit. By default, that is. However, I found it is not quite as straightforward as the article makes it out to be. I have a page web form called UserInformation. This page can be accessed with a user querystring parameter to display user account details for a specific user.

For example, UserInformation. I have created an Account details page type which maps to the UserInformation. It's just plain ugly. So, how do we accomplish this without creating an actual EPiServer page for each user? Next, modify your web. URL rewriting requires that there is a 1-to-1 relationship between an internal URL and it's external, or friendly, counterpart. So, you need a way of going from internal URL to external and back to internal.

For a scenario such as the one in this demonstration you're probably dependant on some data source for performing this URL translation. I've added a page of type Account details to my EPiServer site. I've set the Page name in address for this page to " Account-Information" this is also important, and yes, you'll see why shortly.

In other words, I want URLs like: www. So, if I have the friendly URL www. In this sample I start out the URL rewrite provider class with a static reference to the underlying EPiServer page the page used to display account details :.

The first one is to compose the friendly URL. The second one is to compose the internal URL. Don't ask me where that method name came from, though. Oh yeah, the name "ConvertToExternal" was taken. In my implementation I use my custom URL rewrite behavior for account details pages and the default rewrite behavior for all other requests.

It looks like this:. This code sample is a bit longer than the previous one, but it's actually not that complicated. URL caching is good. However, in the process the FriendlyUrlRewriteProvider removes all querystring parameters except for the id, epslanguage and epstemplate parameters. This is bad. Especially if you're dependant on a querystring parameter named user remember? Unless we deal with this problem the first request to one of our account details pages will work perfectly well. But, if we would hit F5 within 10 seconds or whatever the URL cache timeout is set to be we would get an error.

This is because the internal URL would be fetched from the cache and it would have the user querystring parameter stripped from it. That was easy, wasn't it? Now, to top it off, here's the trivial source code of the account details page UserInformation.

And here's the result note the friendly URL in the address bar and its internal representation at the bottom of the page :.

So, what's so special about all this? On the start page of the web site I've added a number of links to the UserInformation. A scheduled job in EPiServer is essentially a piece of code that will be executed repeatedly at a given time interval, or when an administrator manually executes it through the administrator interface.

I want to have my very own scheduled job appear in the EPiServer administrator interface like so:. In the scheduled job log I want a descriptive message explaining the result of each job execution. In this example I've created a scheduled job which counts the number of pages in the recycle bin.

Each time the job is run I want it to output the number of pages in the recycle bin in the job log:. Note that the log contains the name of the scheduled job , its description and two log entries.

A new log entry is added each time the job is executed. In order to have your new scheduled job which is essentially a class in the EPiServer project's assembly appear in the scheduled job list, the class needs to have the ScheduledPlugin attribute:.

Note that the ScheduledPlugin attribute is used to specify that the class is to be used as a scheduled job and it is also used to provide a name and a description for the scheduled job.

I have also set the SortIndex parameter to ensure that my slick scheduled job appears at the very top of the list. Whenever a scheduled job is triggered to be executed it looks for a static method called Execute in the scheduled job's underlying class. The following job simply counts the number of pages in the recycle bin of the web site:. Log in as an administrator. Locate your scheduled job under Scheduled Jobs on the Admin tab.

Click your scheduled job to access its settings page. Here you can set a schedule for your job and also execute it manually if need be. This is also where you access the scheduled job log by clicking the History tab :. This post explains how to get the simple address of a page, if any. The following code snippet shows how to retrieve the simple address of an EPiServer page. This post shows how to login to an EPiServer site programmatically, for example to execute a scheduled job as a specific user.

However, once it executes according to its schedule it will be run in an anonymous context. Logging on as a specific user through code is an easy task in EPiServer. In fact you do not even have to know the password of the user you want to "impersonate":. Any code following the previous statement will be run as if the "your. In scheduled jobs that require specific user permissions I usually check the PrincipalInfo.

CurrentPrincipal object to see if the job is executed anonymously:. Update: You may also use the BypassAccessCheck parameter to disable permission checking. If you do your code will be able to modify files etc without programmatically logging in. However, I recommend logging in using a designated account when modifying content through code to make version logs easier to interpret.

As Stein Viggo points out in his EPiServer on Steroids post, traditional page type templates can limit editor creativity. Having editors enter values for page properties and placing these values within well-defined templates can do miracles for accessibility and consistency - but you will often find that you have to add more page types or page properties, or implement custom properties, to overcome the limitations of traditional page template design.

However, there are neat ways around it! Extension X3 is one approach to this drag-and-drop building block notice the rhyme! The other approach, which I will focus on here, is using web parts to allow editors to add, re-arrange and customize building blocks to allow for a flexible page layout. Here's what I did to extend it to play around with web parts in EPiServer:.

The most obvious difference when you log in to the edit interface after installing the Web Part Framework module is that you have two additional page types available; Web Part Page and Web Part Page 3 col. I got to admit those are some pretty self-explanatory page type names!

I decided to add a free text editor web part called Editor to the left zone, an RSS feed to the main zone and a Page List web part to the right zone:. However, it doesn't get really cool until you start developing your own web parts and insert them in EPiServer!

Web parts can be created in many different ways. The Web Parts Framework contains a lot of different base classes that you can use to jump start your web part development. However, I'm not a big fan of the cooking-show-I've-already-prepared-this approach, so I'll demonstrate an example where we start developing our web part from scratch.

Let's head into the kitchen! I want to create a web part user control which outputs the current time and also allows the editor to specify the time zone. Yeah, it's not rocket science, but it demonstrates the concept in an intuitive way I hope! First of all, add a new user control named Clock to your EPiServer project. Add two Literal controls to it for displaying a label and the actual time:.

That's all the front-end coding we're going to be doing today. Next, open up the user control's code-behind file. Our user control should inherit the base class EPiServer. However, to make our user control act as a web part we also want to inherit the IWebPart interface:.

Next, right-click the IWebPart interface name and select Implement Interface Explicitly to get the code stubs we need to implement in order to fulfill the interface contract:. The IWebPart interface declares a number of properties that need to be implemented.

Using the automatic properties introduced in. NET 3.

Resolving page URL

Page 1 2 Maybe there are other posts about this, but I thought I'd share an easy way of getting the friendly URL of a page since I've gotten questions about it on numerous occasions:. So, you should probably not ignore the PageLink parameter unless you have to - URL rewriting is probably the most expensive operation carried out by EPiServer. I'm a firm believer in avoiding querystring parameters in URLs, especially for public web sites.

When you are creating a page type in EPiServer you have a lot of configuration settings you can do. You can set the default value, hide it from the Edit interface, make it mandatory and so on.

By using our site, you acknowledge that you have read and understand our Cookie Policy , Privacy Policy , and our Terms of Service. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Using EpiServer 8. I've seen online posts that suggest the following:. UrlHelper' does not contain a definition for 'ContentUrl' and no extension method 'ContentUrl' accepting a first argument of type 'System.

Showing the friendly URL of a Content Reference or Url property in a PropertyList

Ever wanted to introduce some special URL handling in your EPiServer web sites, like browsing pages per category by calling mysite. Well, rejoyce, cause now it's easier than ever before. NET framework 3. Originally built as a part of ASP. In fact, it works splendidly with Web Forms as well - or any other task you can think of. My personal guess is that we might do that eventually - but it's not as straightforward as it seems. First of all the UrlRouting only solves half the problem since we still need to rewrite all outputted html to friendly urls - and secondly, a number of implementations already have either hooked into the url rewriting or made their own based on the original. But enough of me guessing what the product teams considerations are. Fact remains, that you can already get the benefits of UrlRouting today by following these simple steps. The example I'll show is from a project I'm currently working on - finalizing a Wiki for EPiServer which will be totally awesome, btw.

Episerver blog by Ted & Gustaf

GetUrl with just a ContentReference as a parameter will return a url in the same context as the current request that is it the current request in onpageedit then the url will be in onpageedit format. This website is mostly a walkby for all the info you wished about this and didnt know who to ask. Glimpse right here, and also youll undoubtedly uncover it. Using UriSupport.

When you work with EPiServer content data in MVC, the view does not have to take the content data object as view model.

I'm having a problem when trying to render an Url from an Url property in my view. Problem is that I want the friendly URL either it's an internal nor an external link. PageUrl Model. ToString but for the internal link this only gives me the ID to the page.

EPiServer and Custom URLS using ASP.NET UrlRouting

With EPiServer 7 that changes. This method resides in a class in the EPiServer. Html namespace and has a single parameter of type string named classicalUrl. In a view it may look like this:.

There is a bunch of articles how to get started with it in this mode. Default Alloy template allows you to quickly get content API up and running, but the default output result is far from being perfect for real case usage and usually requires customization. Cms dependency to default Alloy site. With the default configuration you get predefined API endpoints and extensive output models. The endpoints support querying and searching content, authorization and works with friendly URLs. The default output shows a lot of data.

How to get the friendly URL of a page in EPiServer CMS

I was really trying to avoid blogging about any more custom properties, things related to PropertyList or Episerver editor UI customization. However, I felt like digging into how easy or hard it would be to show friendly URLs for ContentReference and Url properties in a PropertyList, so I thought I may as well revisit all of the areas I was trying to avoid in one blog post! I should also preface this post by saying that the code here is essentially a code experiment and I'm sharing it with that proviso. Finally, it's worth noting that Episerver don't actually support using the Url property in a PropertyList see this forum answer so it's probably worth keeping that in mind. Here Url is a Url property, and Link is a ContentReference, so our list item looks something like this:. To start with we run into the same issue as Grzegorz, in that we need to resolve friendly URLs before rendering as he explains, this is because the grid formatter doesn't work with Deferreds. This is a bit of hassle because it means we need to resolve URLs from the backend for the initial load, and also from the frontend — when we close the dialog.

Feb 19, - Im retrieving the url by checking if a Simple address exists, if not im using the urlresolver to get the relative path. Personally I don't really see the.

In Episerver, we have a number of different ways of allowing content editors to add and set links on a website. In today's guide, I'm going to cover how to add an Episerver. Url property to a page-type or block, and then how to render that Url on your website so it uses the friendly Url and not the ugly internal Episerver identifier.

Subscribe to RSS

It manages content. Having predictable methods for creating, modifying and retrieving content is crucial for a CMS. Most of the content can probably be accessed using some sort of URL.

Instead, rely on the helpers and extensions that EPiServer 7 provides. PageLink helper. For the text of the link, if you do not supply it with a text string, it will use the PageName property for the page or the Text property for a LinkItem object.





Comments: 1
  1. Meshura

    I have thought and have removed the idea

Thanks! Your comment will appear after verification.
Add a comment

© 2020 Online - Advisor on specific issues.