Article information Article relates to RadEditor 5.x+, RadEditor for ASP.NET AJAX Created by Rumen Jekov
Strip paths in RadEditor and use relative paths instead of absolute.
Article relates to
RadEditor 5.x+, RadEditor for ASP.NET AJAX
By default, Internet Explorer (IE) converts all relative links to absolute on the client. This behavior is due to the DOM engine of the Internet Explorer browser which “fills” the paths (href or src) for the objects in an editing area. Since RadEditor relies in most part to the Internet Explorer's engine, one may observe that the editor converts relative paths to absolute after switching to HTML mode and back to edit mode. Actually, it is Internet Explorer which is converting the links. This problem does not apply to NS/Mozilla/Firefox browsers. For v5, Telerik has employed a flexible mechanism based on regular expressions that strips absolute paths. For better performance the mechanism runs only when the user switches to HTML mode or submits the page. The Attribute Inspector module and the link properties dialog show the default href value as it is provided by the browser - that is - they show absolute paths.
SOLUTION RadEditor for ASP.NET (Classic)
There are many cases where relative paths should be used instead of absolute. For this reason, RadEditor uses two properties which force the links to be stripped on the server. These properties are:
Since these properties operate on the server, before saving the content, while in HTML mode, one may see absolute links on the client. However, once the page is saved, the paths on the server should be relative.
In the example above, RadEditor will strip just the server name from the path. In version 5.x of the editor we provided two new properties which one can set to strip the desired portion of the URL path inserted in RadEditor:
We have enhanced the images and anchor stripping mechanism in RadEditor 6.5.1+ and the ImagesPathToStrip and AnchorPathToStrip properties can receive multiple src / href paths to strip divided by a blank space, e.g ImagesPathToStrip="http://www.domain1.com/wwwtest http://www.domain2.com/wwwtest"
You can put as many src / href paths inside the quotes as many path strings you wish to strip.
If the RadEditor is placed in a page with URL http://www.telerik.com/management/default.aspx and an anchor with URL "pages/radeditor.aspx" is put on the page using the RadEditor, Internet Explorer will change anchor's URL to http://www.telerik.com/management/pages/radeditor.aspx .
If the StripAbsoluteAnchorPaths property is set to true, the RadEditor will change the anchor's URL to:
Basically when using RadEditor as a standalone control there are various types of content management environments it can be integrated to. For example, having an edit ASPX page in a subfolder e.g. http://server/edit/editPage.aspx and then viewing the content in http://server/PublicPage.aspx would result in broken links/images in the public page if the path to be stripped is http://server. For this specific scenario the path to be stripped should be http://server/edit.
The resulting paths in the above mentioned scenario would become server-wide absolute ones. However, one might need to have links that are relative to the page. When such a need arises, the path to be stripped should contain the slash, so that relative paths remain only.
If you insert an image, located at http://localhost/MyApplication/Images/Image.jpg, you will have this whole path in the content area.
If set StripAbsoluteImagesPaths to true and ImagesPathToStrip to http://localhost/MybApplication/, after switching to HTML mode or saving, you will get the path Images/Image.jpg in the content area.
When you switch back to design mode (or you load the content), you will have the path filled back depending on the current page location, i.e. the path will become http://localhost/MyApplication/MyVirtualDirectory/Images/Image.jpg (it will be extended with the Virtual Directory name). However, each time you switch from design mode to html mode and back, you will have the path extended again and again due to a browser limitation.
If you, however, set the ImagesPathToStrip not to contain the slash symbol, e.g. http://localhost/MyApplication, after stripping, the actual image path will become /Images/MyImage.jpg, which will “tell” the browser to look for the image at the WEBSITE_ROOT/Images folder, which will not be correct.
If the images are always located in a subfolder in relation to the current page, you can also set the ImagesPathToStrip in the codebehind to the value of the current page location: editor1.ImagesPathToStrip = "http://" + Request.ServerVariables["SERVER_NAME"] + Request.CurrentExecutionFilePath
By default in RadEditor for ASP.NET AJAX the Image paths are relative. In order to make them absolute you can set the ContentFilters property value to MakeUrlsAbsolute. The ContentFilters allows the developer to set which content filters will be active when the editor loads.
Copyright © 2017, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.